@@ -8,22 +8,21 @@ The `Agent` class is the primary building block in the Loom framework. It repres
8
8
## Creating an Agent
9
9
10
10
``` typescript
11
- import { Agent } from ' loom-agents' ;
11
+ import { Agent } from " loom-agents" ;
12
12
13
13
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" ,
18
17
tools: [
19
18
// Tool definitions
20
19
],
21
20
web_search: {
22
21
enabled: true ,
23
22
config: {
24
- search_context_size: ' medium'
25
- }
26
- }
23
+ search_context_size: " medium" ,
24
+ },
25
+ },
27
26
});
28
27
```
29
28
@@ -33,14 +32,31 @@ The `AgentConfig` interface defines the available configuration options:
33
32
34
33
``` typescript
35
34
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'
41
40
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
44
60
}
45
61
```
46
62
@@ -50,16 +66,26 @@ Agents can process string inputs or more complex request objects:
50
66
51
67
``` typescript
52
68
// 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" );
54
70
55
71
// 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
+ );
63
89
```
64
90
65
91
## Defining Tools
@@ -69,19 +95,19 @@ Tools allow agents to interact with external systems or perform specialized task
69
95
``` typescript
70
96
const tools = [
71
97
{
72
- name: ' fetchWeather' ,
73
- description: ' Get current weather for a location' ,
98
+ name: " fetchWeather" ,
99
+ description: " Get current weather for a location" ,
74
100
parameters: {
75
101
location: {
76
- type: ' string' ,
77
- description: ' City name or coordinates'
78
- }
102
+ type: " string" ,
103
+ description: " City name or coordinates" ,
104
+ },
79
105
},
80
106
callback : async ({ location }) => {
81
107
// Implementation to fetch weather data
82
- return { temperature: 72 , conditions: ' sunny' };
83
- }
84
- }
108
+ return { temperature: 72 , conditions: " sunny" };
109
+ },
110
+ },
85
111
];
86
112
```
87
113
@@ -95,14 +121,15 @@ const agent = new Agent({
95
121
web_search: {
96
122
enabled: true ,
97
123
config: {
98
- search_context_size: ' high' , // 'high', 'medium', or 'low'
124
+ search_context_size: " high" , // 'high', 'medium', or 'low'
99
125
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
+ },
106
133
});
107
134
```
108
135
@@ -112,14 +139,14 @@ Agents can delegate tasks to specialized sub-agents:
112
139
113
140
``` typescript
114
141
const mathAgent = new Agent ({
115
- name: ' MathExpert' ,
116
- purpose: ' Solve complex math problems' ,
142
+ name: " MathExpert" ,
143
+ purpose: " Solve complex math problems" ,
117
144
// ... other config
118
145
});
119
146
120
147
const researchAgent = new Agent ({
121
- name: ' Researcher' ,
122
- purpose: ' Find and summarize information' ,
148
+ name: " Researcher" ,
149
+ purpose: " Find and summarize information" ,
123
150
sub_agents: [mathAgent ],
124
151
// ... other config
125
152
});
@@ -129,6 +156,6 @@ const researchAgent = new Agent({
129
156
130
157
## Related
131
158
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
0 commit comments