Skip to content

Commit 4931edc

Browse files
Update documentation.
1 parent a66064d commit 4931edc

File tree

4 files changed

+155
-106
lines changed

4 files changed

+155
-106
lines changed

src/content/docs/guides/examples.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ console.log(result.final_message);
9999
## Using Traces for Debugging
100100

101101
```typescript
102-
import { Agent, Runner, Tracer } from 'loom-agents';
102+
import { Agent, Runner } from 'loom-agents';
103103

104104
// Create agent and runner
105105
const agent = new Agent({ /*...*/ });
@@ -109,8 +109,11 @@ const runner = new Runner(agent);
109109
const result = await runner.run('Process this data');
110110

111111
// Get and display the trace
112-
const tracer = runner.GetTracer();
113-
console.log(tracer.render());
112+
const lastTrace = runner.getLastTrace();
113+
console.log(lastTrace.render());
114+
115+
// Or get all traces from this runner
116+
const allTraces = runner.getTraces();
114117
```
115118

116119
## Web Search Agent

src/content/docs/reference/agent.mdx

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ The `Agent` class is the primary building block in the Loom framework. It repres
88
## Creating an Agent
99

1010
```typescript
11-
import { Agent } from 'loom-agents';
11+
import { Agent } from "loom-agents";
1212

1313
const agent = new Agent({
14-
name: 'Researcher',
15-
purpose: 'Find and summarize information',
16-
model: 'gpt-4o',
17-
mode: 'completions', // or 'responses'
14+
name: "Researcher",
15+
purpose: "Find and summarize information",
16+
model: "gpt-4o",
1817
tools: [
1918
// Tool definitions
2019
],
2120
web_search: {
2221
enabled: true,
2322
config: {
24-
search_context_size: 'medium'
25-
}
26-
}
23+
search_context_size: "medium",
24+
},
25+
},
2726
});
2827
```
2928

@@ -33,14 +32,31 @@ The `AgentConfig` interface defines the available configuration options:
3332

3433
```typescript
3534
interface AgentConfig {
36-
name: string; // Required: Unique name for the agent
37-
purpose: string; // Required: Defines the agent's objective
38-
sub_agents?: Agent[]; // Optional: Sub-agents that can be called
39-
tools?: ToolCall[]; // Optional: Tools the agent can use
40-
model?: string; // Optional: Default is 'gpt-4o'
35+
name: string; // Required: Unique name for the agent
36+
purpose: string; // Required: Defines the agent's objective
37+
sub_agents?: Agent[]; // Optional: Sub-agents that can be called
38+
tools?: ToolCall[]; // Optional: Tools the agent can use
39+
model?: string; // Optional: Default is 'gpt-4o'
4140
web_search?: WebSearchConfig; // Optional: Web search configuration
42-
timeout_ms?: number; // Optional: Default is 60000ms (1 minute)
43-
mode?: 'responses' | 'completions'; // Optional: API mode, default depends on Loom.api
41+
timeout_ms?: number; // Optional: Default is 60000ms (1 minute)
42+
}
43+
```
44+
45+
## Agent Request and Response
46+
47+
When running an agent, you can use a simple string or a request object:
48+
49+
```typescript
50+
// AgentRequest interface
51+
interface AgentRequest {
52+
context: T[]; // Conversation context
53+
}
54+
55+
// AgentResponse interface
56+
interface AgentResponse {
57+
status: string; // "completed", "error", etc.
58+
final_message: string; // The final output message
59+
context: T[]; // The updated conversation context
4460
}
4561
```
4662

@@ -50,16 +66,26 @@ Agents can process string inputs or more complex request objects:
5066

5167
```typescript
5268
// Simple string input
53-
const result = await agent.run('Find information about quantum computing');
69+
const result = await agent.run("Find information about quantum computing");
5470

5571
// Context-aware request
56-
const result = await agent.run({
57-
context: [
58-
{ role: 'user', content: 'What can you tell me about quantum computing?' },
59-
{ role: 'assistant', content: 'Quantum computing is a type of computing that uses quantum phenomena...' },
60-
{ role: 'user', content: 'How does it compare to classical computing?' }
61-
]
62-
});
72+
const result = await agent.run(
73+
{
74+
context: [
75+
{
76+
role: "user",
77+
content: "What can you tell me about quantum computing?",
78+
},
79+
{
80+
role: "assistant",
81+
content:
82+
"Quantum computing is a type of computing that uses quantum phenomena...",
83+
},
84+
{ role: "user", content: "How does it compare to classical computing?" },
85+
],
86+
},
87+
optionalTraceObject // Optional: For observability
88+
);
6389
```
6490

6591
## Defining Tools
@@ -69,19 +95,19 @@ Tools allow agents to interact with external systems or perform specialized task
6995
```typescript
7096
const tools = [
7197
{
72-
name: 'fetchWeather',
73-
description: 'Get current weather for a location',
98+
name: "fetchWeather",
99+
description: "Get current weather for a location",
74100
parameters: {
75101
location: {
76-
type: 'string',
77-
description: 'City name or coordinates'
78-
}
102+
type: "string",
103+
description: "City name or coordinates",
104+
},
79105
},
80106
callback: async ({ location }) => {
81107
// Implementation to fetch weather data
82-
return { temperature: 72, conditions: 'sunny' };
83-
}
84-
}
108+
return { temperature: 72, conditions: "sunny" };
109+
},
110+
},
85111
];
86112
```
87113

@@ -95,14 +121,15 @@ const agent = new Agent({
95121
web_search: {
96122
enabled: true,
97123
config: {
98-
search_context_size: 'high', // 'high', 'medium', or 'low'
124+
search_context_size: "high", // 'high', 'medium', or 'low'
99125
user_location: {
100-
type: 'approximate',
101-
country: 'US',
102-
city: 'San Francisco'
103-
}
104-
}
105-
}
126+
type: "approximate",
127+
country: "US",
128+
city: "San Francisco",
129+
region: "CA",
130+
},
131+
},
132+
},
106133
});
107134
```
108135

@@ -112,14 +139,14 @@ Agents can delegate tasks to specialized sub-agents:
112139

113140
```typescript
114141
const mathAgent = new Agent({
115-
name: 'MathExpert',
116-
purpose: 'Solve complex math problems',
142+
name: "MathExpert",
143+
purpose: "Solve complex math problems",
117144
// ... other config
118145
});
119146

120147
const researchAgent = new Agent({
121-
name: 'Researcher',
122-
purpose: 'Find and summarize information',
148+
name: "Researcher",
149+
purpose: "Find and summarize information",
123150
sub_agents: [mathAgent],
124151
// ... other config
125152
});
@@ -129,6 +156,6 @@ const researchAgent = new Agent({
129156

130157
## Related
131158

132-
- [Runner](/docs/reference/runner): Orchestrates agent execution
133-
- [Trace](/docs/reference/trace): Provides observability for agent operations
134-
- [Loom](/docs/reference/loom): Global configuration for OpenAI settings
159+
- [Runner](/docs/reference/runner): Orchestrates agent execution with enhanced context management
160+
- [Trace](/docs/reference/trace): Provides structured observability for agent operations
161+
- [Loom](/docs/reference/loom): Global configuration for OpenAI settings and API preferences

src/content/docs/reference/runner.mdx

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ The `Runner` class orchestrates the execution of [Agents](/docs/reference/agent)
88
## Creating a Runner
99

1010
```typescript
11-
import { Agent, Runner } from 'loom-agents';
11+
import { Agent, Runner } from "loom-agents";
1212

1313
const agent = new Agent({
14-
name: 'Assistant',
15-
purpose: 'Help with general tasks',
14+
name: "Assistant",
15+
purpose: "Help with general tasks",
1616
// ... other config
1717
});
1818

1919
const runner = new Runner(agent, {
20-
name: 'MainRunner',
20+
name: "MainRunner",
2121
max_depth: 5,
2222
context: {
23-
user_id: 'user-123',
24-
session_start: Date.now()
25-
}
23+
user_id: "user-123",
24+
session_start: Date.now(),
25+
},
2626
});
2727
```
2828

@@ -32,9 +32,9 @@ The `RunnerConfig` interface defines available configuration options:
3232

3333
```typescript
3434
interface RunnerConfig {
35-
max_depth?: number; // Optional: Maximum number of turns (default: 10)
36-
name?: string; // Optional: Runner name (default: "Runner")
37-
id?: string; // Optional: Unique ID (default: auto-generated UUID)
35+
max_depth?: number; // Optional: Maximum number of turns (default: 10)
36+
name?: string; // Optional: Runner name (default: "Runner")
37+
id?: string; // Optional: Unique ID (default: auto-generated UUID)
3838
context?: Record<string, any>; // Optional: Additional context data
3939
}
4040
```
@@ -45,16 +45,15 @@ The `run` method executes the agent and manages the interaction flow:
4545

4646
```typescript
4747
// Simple string input
48-
const result = await runner.run('Help me write a resume');
48+
const result = await runner.run("Help me write a resume");
4949

5050
// Rich context input
5151
const result = await runner.run({
5252
context: [
53-
{ role: 'user', content: 'I need help with my resume' },
54-
{ role: 'assistant', content: 'I can help! What industry are you in?' },
55-
{ role: 'user', content: 'Software engineering' }
53+
{ role: "user", content: "I need help with my resume" },
54+
{ role: "assistant", content: "I can help! What industry are you in?" },
55+
{ role: "user", content: "Software engineering" },
5656
],
57-
trace: parentTrace // Optional: parent trace for nested execution
5857
});
5958
```
6059

@@ -69,13 +68,11 @@ The Runner handles:
6968

7069
## Handling Results
7170

72-
The `run` method returns:
71+
The `run` method returns a `RunnerResponse` which is a souped-up [AgentResponse](/docs/reference/agent)
7372

7473
```typescript
75-
type RunResult = {
76-
status: string; // "completed", "error", etc.
77-
final_message: string; // The final output message
78-
context: ResponseInputItem[] | ChatCompletionMessageParam[]; // The full conversation context
74+
interface RunnerResponse<T> extends AgentResponse<T> {
75+
trace: Trace; // The execution trace
7976
}
8077
```
8178

@@ -84,12 +81,14 @@ type RunResult = {
8481
The Runner provides methods to access execution details:
8582

8683
```typescript
87-
// Get the conversation history
88-
const messages = runner.GetMessages();
84+
// Get the most recent trace
85+
const lastTrace = runner.getLastTrace();
8986

90-
// Get the tracer for detailed execution logs
91-
const tracer = runner.GetTracer();
92-
console.log(tracer.render()); // Print execution trace
87+
// Get all traces from this runner
88+
const traces = runner.getTraces();
89+
90+
// Render the last trace for debugging
91+
console.log(lastTrace.render());
9392
```
9493

9594
## Execution Depth and Handling
@@ -98,10 +97,12 @@ The Runner prevents infinite loops by enforcing a maximum execution depth:
9897

9998
```typescript
10099
const runner = new Runner(agent, {
101-
max_depth: 5 // Agent will stop after 5 interaction turns
100+
max_depth: 5, // Agent will stop after 5 interaction turns
102101
});
103102
```
104103

104+
If the maximum depth is reached before the agent completes its task, the runner will return the current state with the status from the agent's last response.
105+
105106
## Related
106107

107108
- [Agent](/docs/reference/agent): The core AI component orchestrated by Runners

0 commit comments

Comments
 (0)