simple_acp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.envrc +1 -0
- data/CHANGELOG.md +5 -0
- data/COMMITS.md +196 -0
- data/LICENSE.txt +21 -0
- data/README.md +385 -0
- data/Rakefile +13 -0
- data/docs/api/client-base.md +383 -0
- data/docs/api/index.md +159 -0
- data/docs/api/models.md +286 -0
- data/docs/api/server-base.md +379 -0
- data/docs/api/storage.md +347 -0
- data/docs/assets/images/simple_acp.jpg +0 -0
- data/docs/client/index.md +279 -0
- data/docs/client/sessions.md +324 -0
- data/docs/client/streaming.md +345 -0
- data/docs/client/sync-async.md +308 -0
- data/docs/core-concepts/agents.md +253 -0
- data/docs/core-concepts/events.md +337 -0
- data/docs/core-concepts/index.md +147 -0
- data/docs/core-concepts/messages.md +211 -0
- data/docs/core-concepts/runs.md +278 -0
- data/docs/core-concepts/sessions.md +281 -0
- data/docs/examples.md +659 -0
- data/docs/getting-started/configuration.md +166 -0
- data/docs/getting-started/index.md +62 -0
- data/docs/getting-started/installation.md +95 -0
- data/docs/getting-started/quick-start.md +189 -0
- data/docs/index.md +119 -0
- data/docs/server/creating-agents.md +360 -0
- data/docs/server/http-endpoints.md +411 -0
- data/docs/server/index.md +218 -0
- data/docs/server/multi-turn.md +329 -0
- data/docs/server/streaming.md +315 -0
- data/docs/storage/custom.md +414 -0
- data/docs/storage/index.md +176 -0
- data/docs/storage/memory.md +198 -0
- data/docs/storage/postgresql.md +350 -0
- data/docs/storage/redis.md +287 -0
- data/examples/01_basic/client.rb +88 -0
- data/examples/01_basic/server.rb +100 -0
- data/examples/02_async_execution/client.rb +107 -0
- data/examples/02_async_execution/server.rb +56 -0
- data/examples/03_run_management/client.rb +115 -0
- data/examples/03_run_management/server.rb +84 -0
- data/examples/04_rich_messages/client.rb +160 -0
- data/examples/04_rich_messages/server.rb +180 -0
- data/examples/05_await_resume/client.rb +164 -0
- data/examples/05_await_resume/server.rb +114 -0
- data/examples/06_agent_metadata/client.rb +188 -0
- data/examples/06_agent_metadata/server.rb +192 -0
- data/examples/README.md +252 -0
- data/examples/run_demo.sh +137 -0
- data/lib/simple_acp/client/base.rb +448 -0
- data/lib/simple_acp/client/sse.rb +141 -0
- data/lib/simple_acp/models/agent_manifest.rb +129 -0
- data/lib/simple_acp/models/await.rb +123 -0
- data/lib/simple_acp/models/base.rb +147 -0
- data/lib/simple_acp/models/errors.rb +102 -0
- data/lib/simple_acp/models/events.rb +256 -0
- data/lib/simple_acp/models/message.rb +235 -0
- data/lib/simple_acp/models/message_part.rb +225 -0
- data/lib/simple_acp/models/metadata.rb +161 -0
- data/lib/simple_acp/models/run.rb +298 -0
- data/lib/simple_acp/models/session.rb +137 -0
- data/lib/simple_acp/models/types.rb +210 -0
- data/lib/simple_acp/server/agent.rb +116 -0
- data/lib/simple_acp/server/app.rb +264 -0
- data/lib/simple_acp/server/base.rb +510 -0
- data/lib/simple_acp/server/context.rb +210 -0
- data/lib/simple_acp/server/falcon_runner.rb +61 -0
- data/lib/simple_acp/storage/base.rb +129 -0
- data/lib/simple_acp/storage/memory.rb +108 -0
- data/lib/simple_acp/storage/postgresql.rb +233 -0
- data/lib/simple_acp/storage/redis.rb +178 -0
- data/lib/simple_acp/version.rb +5 -0
- data/lib/simple_acp.rb +91 -0
- data/mkdocs.yml +152 -0
- data/sig/simple_acp.rbs +4 -0
- metadata +418 -0
data/docs/api/models.md
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# Models
|
|
2
|
+
|
|
3
|
+
Data models for ACP entities.
|
|
4
|
+
|
|
5
|
+
## Message
|
|
6
|
+
|
|
7
|
+
Represents a message in the protocol.
|
|
8
|
+
|
|
9
|
+
### Class: SimpleAcp::Models::Message
|
|
10
|
+
|
|
11
|
+
#### Factory Methods
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
# Create user message
|
|
15
|
+
Message.user(*parts)
|
|
16
|
+
Message.user("text")
|
|
17
|
+
Message.user(MessagePart.text("text"), MessagePart.json({...}))
|
|
18
|
+
|
|
19
|
+
# Create agent message
|
|
20
|
+
Message.agent(*parts)
|
|
21
|
+
Message.agent("response")
|
|
22
|
+
|
|
23
|
+
# From hash
|
|
24
|
+
Message.from_hash({ "role" => "user", "parts" => [...] })
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Properties
|
|
28
|
+
|
|
29
|
+
| Property | Type | Description |
|
|
30
|
+
|----------|------|-------------|
|
|
31
|
+
| `role` | `String` | `"user"` or `"agent"` |
|
|
32
|
+
| `parts` | `Array<MessagePart>` | Content parts |
|
|
33
|
+
|
|
34
|
+
#### Instance Methods
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
message.text_content # Combined text from all parts
|
|
38
|
+
message.to_h # Convert to hash
|
|
39
|
+
message.to_json # Convert to JSON
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## MessagePart
|
|
45
|
+
|
|
46
|
+
Content within a message.
|
|
47
|
+
|
|
48
|
+
### Class: SimpleAcp::Models::MessagePart
|
|
49
|
+
|
|
50
|
+
#### Factory Methods
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
# Text content
|
|
54
|
+
MessagePart.text("Hello")
|
|
55
|
+
|
|
56
|
+
# JSON content
|
|
57
|
+
MessagePart.json({ key: "value" })
|
|
58
|
+
|
|
59
|
+
# Image content (base64)
|
|
60
|
+
MessagePart.image(base64_data, mime_type: "image/png")
|
|
61
|
+
|
|
62
|
+
# URL reference
|
|
63
|
+
MessagePart.from_url("https://...", content_type: "image/jpeg")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Properties
|
|
67
|
+
|
|
68
|
+
| Property | Type | Description |
|
|
69
|
+
|----------|------|-------------|
|
|
70
|
+
| `content_type` | `String` | MIME type |
|
|
71
|
+
| `content` | `String` | Inline content |
|
|
72
|
+
| `content_url` | `String` | URL reference |
|
|
73
|
+
| `content_encoding` | `String` | `"plain"` or `"base64"` |
|
|
74
|
+
|
|
75
|
+
#### Instance Methods
|
|
76
|
+
|
|
77
|
+
```ruby
|
|
78
|
+
part.text? # Is text/plain?
|
|
79
|
+
part.json? # Is application/json?
|
|
80
|
+
part.image? # Is image/*?
|
|
81
|
+
part.to_h # Convert to hash
|
|
82
|
+
part.to_json # Convert to JSON
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Run
|
|
88
|
+
|
|
89
|
+
Represents an agent execution.
|
|
90
|
+
|
|
91
|
+
### Class: SimpleAcp::Models::Run
|
|
92
|
+
|
|
93
|
+
#### Properties
|
|
94
|
+
|
|
95
|
+
| Property | Type | Description |
|
|
96
|
+
|----------|------|-------------|
|
|
97
|
+
| `run_id` | `String` | Unique identifier (UUID) |
|
|
98
|
+
| `agent_name` | `String` | Agent that executed |
|
|
99
|
+
| `session_id` | `String` | Associated session |
|
|
100
|
+
| `status` | `String` | Current status |
|
|
101
|
+
| `output` | `Array<Message>` | Output messages |
|
|
102
|
+
| `error` | `Error` | Error if failed |
|
|
103
|
+
| `await_request` | `AwaitRequest` | Await details |
|
|
104
|
+
| `created_at` | `Time` | Creation time |
|
|
105
|
+
| `finished_at` | `Time` | Completion time |
|
|
106
|
+
|
|
107
|
+
#### Status Values
|
|
108
|
+
|
|
109
|
+
- `created` - Run created, not started
|
|
110
|
+
- `in_progress` - Currently executing
|
|
111
|
+
- `completed` - Finished successfully
|
|
112
|
+
- `failed` - Encountered error
|
|
113
|
+
- `awaiting` - Waiting for input
|
|
114
|
+
- `cancelled` - Cancelled by request
|
|
115
|
+
|
|
116
|
+
#### Instance Methods
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
run.terminal? # Is in final state?
|
|
120
|
+
run.completed? # Status is "completed"?
|
|
121
|
+
run.failed? # Status is "failed"?
|
|
122
|
+
run.cancelled? # Status is "cancelled"?
|
|
123
|
+
run.awaiting? # Status is "awaiting"?
|
|
124
|
+
run.to_h # Convert to hash
|
|
125
|
+
run.to_json # Convert to JSON
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Session
|
|
131
|
+
|
|
132
|
+
Maintains state across runs.
|
|
133
|
+
|
|
134
|
+
### Class: SimpleAcp::Models::Session
|
|
135
|
+
|
|
136
|
+
#### Properties
|
|
137
|
+
|
|
138
|
+
| Property | Type | Description |
|
|
139
|
+
|----------|------|-------------|
|
|
140
|
+
| `id` | `String` | Unique identifier |
|
|
141
|
+
| `history` | `Array<Message>` | Conversation history |
|
|
142
|
+
| `state` | `Any` | Custom state data |
|
|
143
|
+
|
|
144
|
+
#### Instance Methods
|
|
145
|
+
|
|
146
|
+
```ruby
|
|
147
|
+
session.add_messages(messages) # Append to history
|
|
148
|
+
session.to_h # Convert to hash
|
|
149
|
+
session.to_json # Convert to JSON
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## AgentManifest
|
|
155
|
+
|
|
156
|
+
Agent metadata and capabilities.
|
|
157
|
+
|
|
158
|
+
### Class: SimpleAcp::Models::AgentManifest
|
|
159
|
+
|
|
160
|
+
#### Properties
|
|
161
|
+
|
|
162
|
+
| Property | Type | Description |
|
|
163
|
+
|----------|------|-------------|
|
|
164
|
+
| `name` | `String` | Agent name |
|
|
165
|
+
| `description` | `String` | Human-readable description |
|
|
166
|
+
| `input_content_types` | `Array<String>` | Accepted MIME types |
|
|
167
|
+
| `output_content_types` | `Array<String>` | Produced MIME types |
|
|
168
|
+
| `metadata` | `Hash` | Custom metadata |
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## Error
|
|
173
|
+
|
|
174
|
+
Error information.
|
|
175
|
+
|
|
176
|
+
### Class: SimpleAcp::Models::Error
|
|
177
|
+
|
|
178
|
+
#### Properties
|
|
179
|
+
|
|
180
|
+
| Property | Type | Description |
|
|
181
|
+
|----------|------|-------------|
|
|
182
|
+
| `code` | `String` | Error code |
|
|
183
|
+
| `message` | `String` | Error message |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Events
|
|
188
|
+
|
|
189
|
+
Event types for streaming.
|
|
190
|
+
|
|
191
|
+
### Event Classes
|
|
192
|
+
|
|
193
|
+
| Class | Type | Description |
|
|
194
|
+
|-------|------|-------------|
|
|
195
|
+
| `RunStartedEvent` | `run_started` | Run began |
|
|
196
|
+
| `MessageCreatedEvent` | `message_created` | New message |
|
|
197
|
+
| `MessagePartEvent` | `message_part` | Message chunk |
|
|
198
|
+
| `MessageCompletedEvent` | `message_completed` | Message done |
|
|
199
|
+
| `RunCompletedEvent` | `run_completed` | Run finished |
|
|
200
|
+
| `RunFailedEvent` | `run_failed` | Run errored |
|
|
201
|
+
| `RunAwaitingEvent` | `run_awaiting` | Awaiting input |
|
|
202
|
+
|
|
203
|
+
### Event Properties
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
# All events
|
|
207
|
+
event.type # Event type string
|
|
208
|
+
|
|
209
|
+
# RunStartedEvent
|
|
210
|
+
event.run_id # Run ID
|
|
211
|
+
|
|
212
|
+
# MessageCreatedEvent, MessageCompletedEvent
|
|
213
|
+
event.message # Message object
|
|
214
|
+
|
|
215
|
+
# MessagePartEvent
|
|
216
|
+
event.part # MessagePart object
|
|
217
|
+
|
|
218
|
+
# RunCompletedEvent, RunFailedEvent, RunAwaitingEvent
|
|
219
|
+
event.run # Run object
|
|
220
|
+
|
|
221
|
+
# RunFailedEvent
|
|
222
|
+
event.error # Error object
|
|
223
|
+
|
|
224
|
+
# RunAwaitingEvent
|
|
225
|
+
event.await_request # AwaitRequest object
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Parsing Events
|
|
229
|
+
|
|
230
|
+
```ruby
|
|
231
|
+
event = SimpleAcp::Models::Events.from_hash({
|
|
232
|
+
"type" => "message_part",
|
|
233
|
+
"part" => { "content_type" => "text/plain", "content" => "Hello" }
|
|
234
|
+
})
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Await Types
|
|
240
|
+
|
|
241
|
+
### AwaitRequest
|
|
242
|
+
|
|
243
|
+
Request for additional input.
|
|
244
|
+
|
|
245
|
+
```ruby
|
|
246
|
+
await_request.type # "message"
|
|
247
|
+
await_request.message # Prompt message
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### AwaitResume
|
|
251
|
+
|
|
252
|
+
Resume payload types.
|
|
253
|
+
|
|
254
|
+
```ruby
|
|
255
|
+
# Message resume
|
|
256
|
+
resume = SimpleAcp::Models::MessageAwaitResume.new(
|
|
257
|
+
message: SimpleAcp::Models::Message.user("response")
|
|
258
|
+
)
|
|
259
|
+
resume.type # "message"
|
|
260
|
+
resume.message # Message object
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Base Model
|
|
266
|
+
|
|
267
|
+
All models inherit from `SimpleAcp::Models::Base`.
|
|
268
|
+
|
|
269
|
+
### Common Methods
|
|
270
|
+
|
|
271
|
+
```ruby
|
|
272
|
+
model.to_h # Convert to hash
|
|
273
|
+
model.to_json # Convert to JSON string
|
|
274
|
+
|
|
275
|
+
# Class methods
|
|
276
|
+
Model.from_hash(hash) # Create from hash
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## See Also
|
|
282
|
+
|
|
283
|
+
- [Messages](../core-concepts/messages.md)
|
|
284
|
+
- [Runs](../core-concepts/runs.md)
|
|
285
|
+
- [Sessions](../core-concepts/sessions.md)
|
|
286
|
+
- [Events](../core-concepts/events.md)
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# Server::Base
|
|
2
|
+
|
|
3
|
+
The main server class for hosting ACP agents.
|
|
4
|
+
|
|
5
|
+
## Class: SimpleAcp::Server::Base
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
SimpleAcp::Server::Base.new(storage: nil)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Parameters:**
|
|
14
|
+
|
|
15
|
+
| Name | Type | Default | Description |
|
|
16
|
+
|------|------|---------|-------------|
|
|
17
|
+
| `storage` | `Storage::Base` | `Storage::Memory.new` | Storage backend |
|
|
18
|
+
|
|
19
|
+
**Example:**
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
# Default memory storage
|
|
23
|
+
server = SimpleAcp::Server::Base.new
|
|
24
|
+
|
|
25
|
+
# With Redis storage
|
|
26
|
+
server = SimpleAcp::Server::Base.new(
|
|
27
|
+
storage: SimpleAcp::Storage::Redis.new(url: ENV['REDIS_URL'])
|
|
28
|
+
)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### Instance Methods
|
|
34
|
+
|
|
35
|
+
#### #agent
|
|
36
|
+
|
|
37
|
+
Register an agent using a block.
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
server.agent(name, description: nil, **options, &block)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Parameters:**
|
|
44
|
+
|
|
45
|
+
| Name | Type | Description |
|
|
46
|
+
|------|------|-------------|
|
|
47
|
+
| `name` | `String` | Unique agent name |
|
|
48
|
+
| `description` | `String` | Human-readable description |
|
|
49
|
+
| `input_content_types` | `Array<String>` | Accepted MIME types |
|
|
50
|
+
| `output_content_types` | `Array<String>` | Produced MIME types |
|
|
51
|
+
| `metadata` | `Hash` | Custom metadata |
|
|
52
|
+
| `&block` | `Block` | Handler block receiving Context |
|
|
53
|
+
|
|
54
|
+
**Returns:** `Agent`
|
|
55
|
+
|
|
56
|
+
**Example:**
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
server.agent("echo", description: "Echoes input") do |context|
|
|
60
|
+
SimpleAcp::Models::Message.agent(context.input.first&.text_content)
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
#### #register
|
|
67
|
+
|
|
68
|
+
Register an agent with a callable object.
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
server.register(name, handler, description: nil, **options)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Parameters:**
|
|
75
|
+
|
|
76
|
+
| Name | Type | Description |
|
|
77
|
+
|------|------|-------------|
|
|
78
|
+
| `name` | `String` | Unique agent name |
|
|
79
|
+
| `handler` | `#call` | Object responding to `call(context)` |
|
|
80
|
+
| `description` | `String` | Human-readable description |
|
|
81
|
+
| `**options` | `Hash` | Same options as `#agent` |
|
|
82
|
+
|
|
83
|
+
**Returns:** `Agent`
|
|
84
|
+
|
|
85
|
+
**Example:**
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
class MyAgent
|
|
89
|
+
def call(context)
|
|
90
|
+
SimpleAcp::Models::Message.agent("Hello!")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
server.register("my-agent", MyAgent.new, description: "My agent")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
#### #unregister
|
|
100
|
+
|
|
101
|
+
Remove a registered agent.
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
server.unregister(name)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Parameters:**
|
|
108
|
+
|
|
109
|
+
| Name | Type | Description |
|
|
110
|
+
|------|------|-------------|
|
|
111
|
+
| `name` | `String` | Agent name to remove |
|
|
112
|
+
|
|
113
|
+
**Returns:** `Agent` or `nil`
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
#### #agents
|
|
118
|
+
|
|
119
|
+
Get all registered agents.
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
server.agents
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Returns:** `Hash<String, Agent>`
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
#### #run_sync
|
|
130
|
+
|
|
131
|
+
Execute an agent synchronously.
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
server.run_sync(agent_name:, input:, session_id: nil)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Parameters:**
|
|
138
|
+
|
|
139
|
+
| Name | Type | Description |
|
|
140
|
+
|------|------|-------------|
|
|
141
|
+
| `agent_name` | `String` | Agent to execute |
|
|
142
|
+
| `input` | `Array<Message>` | Input messages |
|
|
143
|
+
| `session_id` | `String` | Optional session ID |
|
|
144
|
+
|
|
145
|
+
**Returns:** `Models::Run`
|
|
146
|
+
|
|
147
|
+
**Example:**
|
|
148
|
+
|
|
149
|
+
```ruby
|
|
150
|
+
run = server.run_sync(
|
|
151
|
+
agent_name: "echo",
|
|
152
|
+
input: [SimpleAcp::Models::Message.user("Hello")]
|
|
153
|
+
)
|
|
154
|
+
puts run.output.first.text_content
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
#### #run_async
|
|
160
|
+
|
|
161
|
+
Start an agent execution without waiting.
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
server.run_async(agent_name:, input:, session_id: nil)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Parameters:** Same as `#run_sync`
|
|
168
|
+
|
|
169
|
+
**Returns:** `Models::Run` (status will be `in_progress`)
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
#### #run_stream
|
|
174
|
+
|
|
175
|
+
Execute an agent with streaming events.
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
server.run_stream(agent_name:, input:, session_id: nil, &block)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Parameters:**
|
|
182
|
+
|
|
183
|
+
| Name | Type | Description |
|
|
184
|
+
|------|------|-------------|
|
|
185
|
+
| `agent_name` | `String` | Agent to execute |
|
|
186
|
+
| `input` | `Array<Message>` | Input messages |
|
|
187
|
+
| `session_id` | `String` | Optional session ID |
|
|
188
|
+
| `&block` | `Block` | Event handler |
|
|
189
|
+
|
|
190
|
+
**Returns:** `Models::Run`
|
|
191
|
+
|
|
192
|
+
**Example:**
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
server.run_stream(
|
|
196
|
+
agent_name: "chat",
|
|
197
|
+
input: messages
|
|
198
|
+
) do |event|
|
|
199
|
+
case event
|
|
200
|
+
when SimpleAcp::Models::MessagePartEvent
|
|
201
|
+
print event.part.content
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
#### #resume_sync
|
|
209
|
+
|
|
210
|
+
Resume an awaiting run synchronously.
|
|
211
|
+
|
|
212
|
+
```ruby
|
|
213
|
+
server.resume_sync(run_id:, await_resume:)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**Parameters:**
|
|
217
|
+
|
|
218
|
+
| Name | Type | Description |
|
|
219
|
+
|------|------|-------------|
|
|
220
|
+
| `run_id` | `String` | Run to resume |
|
|
221
|
+
| `await_resume` | `AwaitResume` | Resume payload |
|
|
222
|
+
|
|
223
|
+
**Returns:** `Models::Run`
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
#### #resume_stream
|
|
228
|
+
|
|
229
|
+
Resume an awaiting run with streaming.
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
server.resume_stream(run_id:, await_resume:, &block)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Parameters:** Same as `#resume_sync` plus event block
|
|
236
|
+
|
|
237
|
+
**Returns:** `Models::Run`
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
#### #cancel_run
|
|
242
|
+
|
|
243
|
+
Cancel an in-progress run.
|
|
244
|
+
|
|
245
|
+
```ruby
|
|
246
|
+
server.cancel_run(run_id)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**Parameters:**
|
|
250
|
+
|
|
251
|
+
| Name | Type | Description |
|
|
252
|
+
|------|------|-------------|
|
|
253
|
+
| `run_id` | `String` | Run to cancel |
|
|
254
|
+
|
|
255
|
+
**Returns:** `Models::Run`
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
#### #to_app
|
|
260
|
+
|
|
261
|
+
Get the Rack application.
|
|
262
|
+
|
|
263
|
+
```ruby
|
|
264
|
+
server.to_app
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Returns:** `Rack::Builder`
|
|
268
|
+
|
|
269
|
+
**Example:**
|
|
270
|
+
|
|
271
|
+
```ruby
|
|
272
|
+
# In config.ru
|
|
273
|
+
run server.to_app
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
#### #run
|
|
279
|
+
|
|
280
|
+
Start the HTTP server.
|
|
281
|
+
|
|
282
|
+
```ruby
|
|
283
|
+
server.run(port: 8000, host: '0.0.0.0', **options)
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Parameters:**
|
|
287
|
+
|
|
288
|
+
| Name | Type | Default | Description |
|
|
289
|
+
|------|------|---------|-------------|
|
|
290
|
+
| `port` | `Integer` | `8000` | Listen port |
|
|
291
|
+
| `host` | `String` | `'0.0.0.0'` | Bind address |
|
|
292
|
+
|
|
293
|
+
**Example:**
|
|
294
|
+
|
|
295
|
+
```ruby
|
|
296
|
+
server.run(port: 3000)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Class: SimpleAcp::Server::Context
|
|
302
|
+
|
|
303
|
+
Execution context passed to agent handlers.
|
|
304
|
+
|
|
305
|
+
### Properties
|
|
306
|
+
|
|
307
|
+
| Property | Type | Description |
|
|
308
|
+
|----------|------|-------------|
|
|
309
|
+
| `input` | `Array<Message>` | Input messages |
|
|
310
|
+
| `session` | `Session` | Current session or nil |
|
|
311
|
+
| `session_id` | `String` | Session ID or nil |
|
|
312
|
+
| `history` | `Array<Message>` | Session history |
|
|
313
|
+
| `state` | `Any` | Session state |
|
|
314
|
+
| `run_id` | `String` | Current run ID |
|
|
315
|
+
| `agent_name` | `String` | Current agent name |
|
|
316
|
+
|
|
317
|
+
### Methods
|
|
318
|
+
|
|
319
|
+
#### #set_state
|
|
320
|
+
|
|
321
|
+
Update session state.
|
|
322
|
+
|
|
323
|
+
```ruby
|
|
324
|
+
context.set_state(new_state)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
#### #await_message
|
|
328
|
+
|
|
329
|
+
Request additional input (for streaming handlers).
|
|
330
|
+
|
|
331
|
+
```ruby
|
|
332
|
+
result = context.await_message(prompt_message)
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
#### #resume_message
|
|
336
|
+
|
|
337
|
+
Get the message from a resume operation.
|
|
338
|
+
|
|
339
|
+
```ruby
|
|
340
|
+
message = context.resume_message
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## Class: SimpleAcp::Server::RunYield
|
|
346
|
+
|
|
347
|
+
Wrapper for yielded messages in streaming handlers.
|
|
348
|
+
|
|
349
|
+
### Constructor
|
|
350
|
+
|
|
351
|
+
```ruby
|
|
352
|
+
SimpleAcp::Server::RunYield.new(messages)
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Parameters:**
|
|
356
|
+
|
|
357
|
+
| Name | Type | Description |
|
|
358
|
+
|------|------|-------------|
|
|
359
|
+
| `messages` | `Message` or `Array<Message>` | Messages to yield |
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Class: SimpleAcp::Server::RunYieldAwait
|
|
364
|
+
|
|
365
|
+
Signal to await client input.
|
|
366
|
+
|
|
367
|
+
### Constructor
|
|
368
|
+
|
|
369
|
+
```ruby
|
|
370
|
+
SimpleAcp::Server::RunYieldAwait.new(await_request)
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## See Also
|
|
376
|
+
|
|
377
|
+
- [Creating Agents](../server/creating-agents.md)
|
|
378
|
+
- [Streaming Responses](../server/streaming.md)
|
|
379
|
+
- [HTTP Endpoints](../server/http-endpoints.md)
|