Skip to content

Commit

Permalink
docs: fix agent
Browse files Browse the repository at this point in the history
Signed-off-by: Ismael Faro <[email protected]>
  • Loading branch information
ismaelfaro committed Dec 3, 2024
1 parent e5de9e3 commit aa1c1b1
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,58 +82,58 @@ Subscribes to agent events for monitoring and debugging.

```ts
const response = await agent
.run(
{ prompt },
{
execution: {
maxRetriesPerStep: 3,
totalMaxRetries: 10,
maxIterations: 20,
},
signal: AbortSignal.timeout(2 * 60 * 1000),
},
)
.observe((emitter) => {
emitter.on("start", () => {
reader.write(`Agent 🤖 : `, "starting new iteration");
});
emitter.on("error", ({ error }) => {
reader.write(`Agent 🤖 : `, FrameworkError.ensure(error).dump());
});
emitter.on("retry", () => {
reader.write(`Agent 🤖 : `, "retrying the action...");
});
emitter.on("update", async ({ data, update, meta }) => {
// log 'data' to see the whole state
// to log only valid runs (no errors), check if meta.success === true
reader.write(`Agent (${update.key}) 🤖 : `, update.value);
});
emitter.on("partialUpdate", ({ data, update, meta }) => {
// ideal for streaming (line by line)
// log 'data' to see the whole state
// to log only valid runs (no errors), check if meta.success === true
// reader.write(`Agent (partial ${update.key}) 🤖 : `, update.value);
});

// To observe all events (uncomment following block)
// emitter.match("*.*", async (data: unknown, event) => {
// logger.trace(event, `Received event "${event.path}"`);
// });
});
.run(
{ prompt },
{
execution: {
maxRetriesPerStep: 3,
totalMaxRetries: 10,
maxIterations: 20,
},
signal: AbortSignal.timeout(2 * 60 * 1000),
},
)
.observe((emitter) => {
emitter.on("start", () => {
reader.write(`Agent 🤖 : `, "starting new iteration");
});
emitter.on("error", ({ error }) => {
reader.write(`Agent 🤖 : `, FrameworkError.ensure(error).dump());
});
emitter.on("retry", () => {
reader.write(`Agent 🤖 : `, "retrying the action...");
});
emitter.on("update", async ({ data, update, meta }) => {
// log 'data' to see the whole state
// to log only valid runs (no errors), check if meta.success === true
reader.write(`Agent (${update.key}) 🤖 : `, update.value);
});
emitter.on("partialUpdate", ({ data, update, meta }) => {
// ideal for streaming (line by line)
// log 'data' to see the whole state
// to log only valid runs (no errors), check if meta.success === true
// reader.write(`Agent (partial ${update.key}) 🤖 : `, update.value);
});

// To observe all events (uncomment following block)
// emitter.match("*.*", async (data: unknown, event) => {
// logger.trace(event, `Received event "${event.path}"`);
// });
});
```

## Events

Agent emits various events through its Emitter:

| Event | Description | Payload |
| --------------- | -------------------------- | ------------------------- |
| `start` | New iteration started | `void` |
| `error` | Error with framework error dump | `{ error }` |
| `retry` | Retry attempt initiated | `void` |
| `update` | Full state update with metadata | `{ data, update: {key, value}, meta }` |
| `partialUpdate` | Streaming line-by-line update | `{ data, update: {key, value}, meta }` |
| `*.*` | Optional catch-all event matcher | `data, event` |
| Event | Description | Payload |
| --------------- | -------------------------------- | -------------------------------------- |
| `start` | New iteration started | `void` |
| `error` | Error with framework error dump | `{ error }` |
| `retry` | Retry attempt initiated | `void` |
| `update` | Full state update with metadata | `{ data, update: {key, value}, meta }` |
| `partialUpdate` | Streaming line-by-line update | `{ data, update: {key, value}, meta }` |
| `*.*` | Optional catch-all event matcher | `data, event` |

## Implementation Example

Expand Down

0 comments on commit aa1c1b1

Please sign in to comment.