Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ gh skills clone pelikhan/rig
```ts
import {
agent,
configureAgent,
defineTool,
p,
s,
} from "rig";
import { addons, oncePerSession, repair, steering, timeout } from "rig/addons";
import { addons, oncePerAgent, repair, steering, timeout } from "rig/addons";
```

- `agent(spec)` creates a typed agent function.
- `s.*` defines input/output schemas. Omit `input`/`output` when free-form strings are enough.
- `p.*` creates declarative prompt intents for prompt templates or inputs.
- `p()` and ``p`...` `` create a prompt builder with `var`, `write`, and `region` primitives for assembling prompts.
- ``p`...` `` also works in `instructions` to embed prompt intents directly: `` instructions: p`Review ${p.bash("git status")}` ``.
- `defineTool(name, config)` matches the Copilot SDK helper and accepts rig `s.*` schemas for `parameters`.
- `addons` accepts express-like `(context, next)` turn addons for steering, inline validation, and Copilot session access.
- `configureAgent(factory)` selects the SDK adapter used to instantiate runtime agents.
- `defineTool(name, config)` creates an SDK-neutral tool definition and accepts rig `s.*` schemas for `parameters`.
- `addons` accepts express-like `(context, next)` turn addons for steering, inline validation, and runtime agent access.
- `rig` starts with no default addons.
- `rig/addons` provides optional addon helpers: `oncePerSession`, `repair`, `steering`, `timeout`, and `addons.{oncePerSession,repair,steering,timeout}`.
- `rig/addons` provides optional addon helpers: `oncePerAgent`, `repair`, `steering`, `timeout`, and `addons.{oncePerAgent,repair,steering,timeout}`.
- `p\`...\`` returns a prompt builder and renders intent values when coerced to string; prefer `${p.read(...)}` / `${p.bash(...)}` when the context source is already known.

## Embedding in markdown
Expand Down Expand Up @@ -188,19 +190,17 @@ const review = agent({
});
```

For direct SDK access, use `oncePerSession(...)` to register with the session once:
Use `oncePerAgent(...)` to register with the runtime agent once:

```ts
const review = agent({
addons: oncePerSession((session) => {
session.on?.((event) => {
// custom event handling
});
addons: oncePerAgent((runtimeAgent) => {
// Register adapter-specific behavior here.
}),
});
```

Per-turn addons still receive `context.session` directly, and you can also register addons after creating the agent:
Per-turn addons receive `context.agent`, and you can also register addons after creating the agent:

```ts
const timingAddon = async (context, next) => {
Expand All @@ -211,9 +211,40 @@ const review = agent({});
review.use(timingAddon);
```

## Copilot SDK runtime
## Agent implementations

`rig` is specialized for Copilot SDK sessions inside sandboxed agentic workflows.
Rig runs only against a minimal interface:

```ts
interface Agent {
ask(prompt: string, options?: { signal?: AbortSignal }): Promise<string>;
close(): Promise<void>;
}
```

Configure any SDK adapter by passing a factory that creates one `Agent` per invocation:

```ts
configureAgent(async ({ model, systemMessage, tools }) => {
return new MySdkAgent({ model, systemMessage, tools });
});
```

Rig includes factories for Copilot, pi-agent, and Anthropic:

```ts
import { configureAgent } from "rig";
import { anthropicEngine } from "rig/engines/anthropic";
import { piEngine } from "rig/engines/pi";

configureAgent(piEngine({ provider: "anthropic" }));
// or, using ANTHROPIC_API_KEY:
configureAgent(anthropicEngine());
```

`piEngine()` uses the maintained `@earendil-works/pi-agent-core` package and requires the provider for model lookup. `anthropicEngine()` uses `@anthropic-ai/sdk`. Both adapters preserve conversation state across repair turns and map Rig tools to their SDK tool runners.

## Copilot SDK adapter

By default it connects to an already-running Copilot server via HTTP (`COPILOT_SDK_URI`, then `localhost:7777`).
Pass `--server` to spawn the server over stdio when launching a program.
Expand Down
Loading
Loading