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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.envrc +1 -0
  3. data/CHANGELOG.md +5 -0
  4. data/COMMITS.md +196 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +385 -0
  7. data/Rakefile +13 -0
  8. data/docs/api/client-base.md +383 -0
  9. data/docs/api/index.md +159 -0
  10. data/docs/api/models.md +286 -0
  11. data/docs/api/server-base.md +379 -0
  12. data/docs/api/storage.md +347 -0
  13. data/docs/assets/images/simple_acp.jpg +0 -0
  14. data/docs/client/index.md +279 -0
  15. data/docs/client/sessions.md +324 -0
  16. data/docs/client/streaming.md +345 -0
  17. data/docs/client/sync-async.md +308 -0
  18. data/docs/core-concepts/agents.md +253 -0
  19. data/docs/core-concepts/events.md +337 -0
  20. data/docs/core-concepts/index.md +147 -0
  21. data/docs/core-concepts/messages.md +211 -0
  22. data/docs/core-concepts/runs.md +278 -0
  23. data/docs/core-concepts/sessions.md +281 -0
  24. data/docs/examples.md +659 -0
  25. data/docs/getting-started/configuration.md +166 -0
  26. data/docs/getting-started/index.md +62 -0
  27. data/docs/getting-started/installation.md +95 -0
  28. data/docs/getting-started/quick-start.md +189 -0
  29. data/docs/index.md +119 -0
  30. data/docs/server/creating-agents.md +360 -0
  31. data/docs/server/http-endpoints.md +411 -0
  32. data/docs/server/index.md +218 -0
  33. data/docs/server/multi-turn.md +329 -0
  34. data/docs/server/streaming.md +315 -0
  35. data/docs/storage/custom.md +414 -0
  36. data/docs/storage/index.md +176 -0
  37. data/docs/storage/memory.md +198 -0
  38. data/docs/storage/postgresql.md +350 -0
  39. data/docs/storage/redis.md +287 -0
  40. data/examples/01_basic/client.rb +88 -0
  41. data/examples/01_basic/server.rb +100 -0
  42. data/examples/02_async_execution/client.rb +107 -0
  43. data/examples/02_async_execution/server.rb +56 -0
  44. data/examples/03_run_management/client.rb +115 -0
  45. data/examples/03_run_management/server.rb +84 -0
  46. data/examples/04_rich_messages/client.rb +160 -0
  47. data/examples/04_rich_messages/server.rb +180 -0
  48. data/examples/05_await_resume/client.rb +164 -0
  49. data/examples/05_await_resume/server.rb +114 -0
  50. data/examples/06_agent_metadata/client.rb +188 -0
  51. data/examples/06_agent_metadata/server.rb +192 -0
  52. data/examples/README.md +252 -0
  53. data/examples/run_demo.sh +137 -0
  54. data/lib/simple_acp/client/base.rb +448 -0
  55. data/lib/simple_acp/client/sse.rb +141 -0
  56. data/lib/simple_acp/models/agent_manifest.rb +129 -0
  57. data/lib/simple_acp/models/await.rb +123 -0
  58. data/lib/simple_acp/models/base.rb +147 -0
  59. data/lib/simple_acp/models/errors.rb +102 -0
  60. data/lib/simple_acp/models/events.rb +256 -0
  61. data/lib/simple_acp/models/message.rb +235 -0
  62. data/lib/simple_acp/models/message_part.rb +225 -0
  63. data/lib/simple_acp/models/metadata.rb +161 -0
  64. data/lib/simple_acp/models/run.rb +298 -0
  65. data/lib/simple_acp/models/session.rb +137 -0
  66. data/lib/simple_acp/models/types.rb +210 -0
  67. data/lib/simple_acp/server/agent.rb +116 -0
  68. data/lib/simple_acp/server/app.rb +264 -0
  69. data/lib/simple_acp/server/base.rb +510 -0
  70. data/lib/simple_acp/server/context.rb +210 -0
  71. data/lib/simple_acp/server/falcon_runner.rb +61 -0
  72. data/lib/simple_acp/storage/base.rb +129 -0
  73. data/lib/simple_acp/storage/memory.rb +108 -0
  74. data/lib/simple_acp/storage/postgresql.rb +233 -0
  75. data/lib/simple_acp/storage/redis.rb +178 -0
  76. data/lib/simple_acp/version.rb +5 -0
  77. data/lib/simple_acp.rb +91 -0
  78. data/mkdocs.yml +152 -0
  79. data/sig/simple_acp.rbs +4 -0
  80. metadata +418 -0
@@ -0,0 +1,252 @@
1
+ # SimpleAcp Examples
2
+
3
+ > **CAUTION:** This project is under active development. The API and documentation may not necessarily reflect the current codebase.
4
+
5
+ This directory contains example programs demonstrating SimpleAcp features.
6
+
7
+ Each example is organized in its own subdirectory with both `server.rb` and `client.rb` files.
8
+
9
+ ## Quick Start
10
+
11
+ Use the unified `run_demo.sh` script to run any demo:
12
+
13
+ ```bash
14
+ # From the project root
15
+ ./examples/run_demo.sh 1 # Run demo 1 (01_basic)
16
+ ./examples/run_demo.sh 4 # Run demo 4 (04_rich_messages)
17
+
18
+ # Or from the examples directory
19
+ cd examples
20
+ ./run_demo.sh 1
21
+ ```
22
+
23
+ ### Available Commands
24
+
25
+ | Command | Description |
26
+ |---------|-------------|
27
+ | `./run_demo.sh <1-6>` | Run a specific demo by number |
28
+ | `./run_demo.sh --list` | List all available demos |
29
+ | `./run_demo.sh --all` | Run all demos sequentially |
30
+ | `./run_demo.sh --help` | Show usage information |
31
+
32
+ ## Examples
33
+
34
+ ### 01_basic
35
+
36
+ Basic server and client demonstrating core SimpleAcp functionality.
37
+
38
+ **Server** (`01_basic/server.rb`) - Registers five agents:
39
+
40
+ | Agent | Description |
41
+ |-------|-------------|
42
+ | `echo` | Echoes input messages back (demonstrates streaming with Enumerator) |
43
+ | `greeter` | Greets the user by name (demonstrates simple responses) |
44
+ | `counter` | Counts invocations (demonstrates session state) |
45
+ | `gettysburg` | Recites the Gettysburg Address word by word with 0.5s delay (demonstrates streaming) |
46
+ | `assistant` | Remembers conversation history (demonstrates multi-turn conversations) |
47
+
48
+ **Client** (`01_basic/client.rb`) - Demonstrates:
49
+
50
+ - Health check with `ping`
51
+ - Listing available agents
52
+ - Synchronous runs with `run_sync`
53
+ - Streaming responses with `run_stream`
54
+ - Session management for stateful interactions
55
+
56
+ **Usage:**
57
+
58
+ ```bash
59
+ ./examples/run_demo.sh 1
60
+ ```
61
+
62
+ ---
63
+
64
+ ### 02_async_execution
65
+
66
+ Demonstrates asynchronous (non-blocking) execution patterns.
67
+
68
+ **Server** (`02_async_execution/server.rb`) - Registers:
69
+
70
+ | Agent | Description |
71
+ |-------|-------------|
72
+ | `slow-worker` | Simulates a 3-second task with progress updates |
73
+ | `quick-status` | Returns status immediately |
74
+
75
+ **Client** (`02_async_execution/client.rb`) - Demonstrates:
76
+
77
+ - Async execution with `run_async`
78
+ - Manual polling with `run_status`
79
+ - Waiting for completion with `wait_for_run`
80
+ - Running multiple tasks concurrently
81
+
82
+ **Usage:**
83
+
84
+ ```bash
85
+ ./examples/run_demo.sh 2
86
+ ```
87
+
88
+ ---
89
+
90
+ ### 03_run_management
91
+
92
+ Demonstrates run lifecycle management including cancellation and event history.
93
+
94
+ **Server** (`03_run_management/server.rb`) - Registers:
95
+
96
+ | Agent | Description |
97
+ |-------|-------------|
98
+ | `cancellable-task` | A long-running task that checks for cancellation |
99
+ | `event-generator` | Generates multiple events for history tracking |
100
+
101
+ **Client** (`03_run_management/client.rb`) - Demonstrates:
102
+
103
+ - Cancelling a running task with `run_cancel`
104
+ - Checking `context.cancelled?` in the agent
105
+ - Retrieving event history with `run_events`
106
+ - Event pagination with limit and offset
107
+
108
+ **Usage:**
109
+
110
+ ```bash
111
+ ./examples/run_demo.sh 3
112
+ ```
113
+
114
+ ---
115
+
116
+ ### 04_rich_messages
117
+
118
+ Demonstrates different message part types and content negotiation.
119
+
120
+ **Server** (`04_rich_messages/server.rb`) - Registers:
121
+
122
+ | Agent | Description |
123
+ |-------|-------------|
124
+ | `json-data` | Returns structured JSON data |
125
+ | `image-generator` | Generates SVG images as base64 |
126
+ | `link-provider` | Returns URL references with metadata |
127
+ | `multi-format` | Returns data in multiple formats (text, JSON, HTML) |
128
+
129
+ **Client** (`04_rich_messages/client.rb`) - Demonstrates:
130
+
131
+ - Receiving and parsing JSON content
132
+ - Handling base64 encoded data
133
+ - Working with URL references and metadata
134
+ - Multi-part messages with different content types
135
+ - Inspecting agent content type capabilities
136
+
137
+ **Usage:**
138
+
139
+ ```bash
140
+ ./examples/run_demo.sh 4
141
+ ```
142
+
143
+ ---
144
+
145
+ ### 05_await_resume
146
+
147
+ Demonstrates the await/resume pattern for interactive multi-step flows.
148
+
149
+ **Server** (`05_await_resume/server.rb`) - Registers:
150
+
151
+ | Agent | Description |
152
+ |-------|-------------|
153
+ | `greeter` | Asks for your name, then greets you |
154
+ | `survey` | A multi-step survey collecting multiple pieces of information |
155
+ | `confirmer` | Asks for confirmation before performing an action |
156
+
157
+ **Client** (`05_await_resume/client.rb`) - Demonstrates:
158
+
159
+ - Detecting when a run is in "awaiting" status
160
+ - Resuming with `run_resume_sync`
161
+ - Multi-step interactive flows using state
162
+ - Confirmation dialogs
163
+ - Streaming resume with `run_resume_stream`
164
+
165
+ **Usage:**
166
+
167
+ ```bash
168
+ ./examples/run_demo.sh 5
169
+ ```
170
+
171
+ ---
172
+
173
+ ### 06_agent_metadata
174
+
175
+ Demonstrates rich agent metadata and content type negotiation.
176
+
177
+ **Server** (`06_agent_metadata/server.rb`) - Registers:
178
+
179
+ | Agent | Description |
180
+ |-------|-------------|
181
+ | `text-analyzer` | Full-featured agent with comprehensive metadata |
182
+ | `simple-echo` | Minimal agent for comparison |
183
+ | `json-processor` | Agent with specific content type requirements |
184
+
185
+ **Client** (`06_agent_metadata/client.rb`) - Demonstrates:
186
+
187
+ - Retrieving full agent metadata with `agent(name)`
188
+ - Inspecting author, contributors, capabilities, links
189
+ - Content type negotiation (`accepts_content_type?`, `produces_content_type?`)
190
+ - Metadata fields: documentation, license, domains, tags, dependencies
191
+
192
+ **Usage:**
193
+
194
+ ```bash
195
+ ./examples/run_demo.sh 6
196
+ ```
197
+
198
+ ---
199
+
200
+ ## Running Examples
201
+
202
+ ### Using the Demo Runner (Recommended)
203
+
204
+ The `run_demo.sh` script handles starting the server, waiting for it to be ready, running the client, and cleanup:
205
+
206
+ ```bash
207
+ # Run a specific demo by number
208
+ ./examples/run_demo.sh 1
209
+
210
+ # List available demos
211
+ ./examples/run_demo.sh --list
212
+
213
+ # Run all demos sequentially
214
+ ./examples/run_demo.sh --all
215
+ ```
216
+
217
+ The script can be executed from either the project root or from within the examples directory.
218
+
219
+ ### Running Manually
220
+
221
+ You can also run server and client manually in separate terminals:
222
+
223
+ ```bash
224
+ # Terminal 1: Start server
225
+ ruby examples/01_basic/server.rb
226
+
227
+ # Terminal 2: Run client
228
+ ruby examples/01_basic/client.rb
229
+ ```
230
+
231
+ ## Feature Coverage
232
+
233
+ | Feature | Example |
234
+ |---------|---------|
235
+ | Basic agent registration | 01_basic |
236
+ | Streaming responses | 01_basic |
237
+ | Session state | 01_basic |
238
+ | Conversation history | 01_basic |
239
+ | Async execution | 02_async_execution |
240
+ | Polling (`run_status`, `wait_for_run`) | 02_async_execution |
241
+ | Concurrent runs | 02_async_execution |
242
+ | Run cancellation | 03_run_management |
243
+ | Event history | 03_run_management |
244
+ | JSON message parts | 04_rich_messages |
245
+ | Binary/base64 data | 04_rich_messages |
246
+ | URL references | 04_rich_messages |
247
+ | Content type negotiation | 04_rich_messages, 06_agent_metadata |
248
+ | Await/resume pattern | 05_await_resume |
249
+ | Multi-step flows | 05_await_resume |
250
+ | Agent metadata | 06_agent_metadata |
251
+ | Author/contributor info | 06_agent_metadata |
252
+ | Capabilities and dependencies | 06_agent_metadata |
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env bash
2
+ # Run a SimpleAcp demo by number
3
+ #
4
+ # Usage: ./examples/run_demo.sh <demo_number>
5
+ # ./examples/run_demo.sh --list
6
+ #
7
+ # Examples:
8
+ # ./examples/run_demo.sh 1 # Run 01_basic demo
9
+ # ./examples/run_demo.sh 4 # Run 04_rich_messages demo
10
+ # ./examples/run_demo.sh --list # List available demos
11
+
12
+ set -e
13
+
14
+ # Calculate project directory ONCE at script start (before any cd commands)
15
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
16
+ PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)"
17
+
18
+ # Demo directory mapping
19
+ declare -A DEMOS=(
20
+ [1]="01_basic"
21
+ [2]="02_async_execution"
22
+ [3]="03_run_management"
23
+ [4]="04_rich_messages"
24
+ [5]="05_await_resume"
25
+ [6]="06_agent_metadata"
26
+ )
27
+
28
+ # Demo descriptions
29
+ declare -A DESCRIPTIONS=(
30
+ [1]="Basic - echo, greeter, counter, streaming, sessions"
31
+ [2]="Async Execution - run_async, polling, wait_for_run"
32
+ [3]="Run Management - cancellation, event history"
33
+ [4]="Rich Messages - JSON, images, URLs, multi-part"
34
+ [5]="Await/Resume - interactive multi-step flows"
35
+ [6]="Agent Metadata - full manifests, content types"
36
+ )
37
+
38
+ show_usage() {
39
+ cat <<EOF
40
+ Usage: $0 <demo_number|--list|--all>
41
+
42
+ Options:
43
+ <number> Run demo 1-6
44
+ --list List available demos
45
+ --all Run all demos sequentially
46
+
47
+ Available demos:
48
+ EOF
49
+ for i in {1..6}; do
50
+ echo " $i) ${DEMOS[$i]} - ${DESCRIPTIONS[$i]}"
51
+ done
52
+ }
53
+
54
+ run_demo() {
55
+ local demo_num=$1
56
+ local demo_dir=${DEMOS[$demo_num]}
57
+
58
+ if [[ -z "$demo_dir" ]]; then
59
+ echo "Error: Invalid demo number '$demo_num'"
60
+ echo "Valid options: 1-6"
61
+ exit 1
62
+ fi
63
+
64
+ cd "$PROJECT_DIR"
65
+
66
+ # Check if demo directory exists
67
+ if [[ ! -d "examples/$demo_dir" ]]; then
68
+ echo "Error: Demo directory 'examples/$demo_dir' not found"
69
+ exit 1
70
+ fi
71
+
72
+ echo "=========================================="
73
+ echo "Running Demo $demo_num: $demo_dir"
74
+ echo "${DESCRIPTIONS[$demo_num]}"
75
+ echo "=========================================="
76
+ echo
77
+
78
+ # Clean up any leftover process on port 8000
79
+ lsof -ti:8000 | xargs kill -9 2>/dev/null || true
80
+
81
+ echo "Starting server..."
82
+ ruby "examples/$demo_dir/server.rb" &
83
+ SERVER_PID=$!
84
+
85
+ # Wait for server to be ready
86
+ echo "Waiting for server to start..."
87
+ for i in {1..30}; do
88
+ if curl -s http://localhost:8000/ping >/dev/null 2>&1; then
89
+ echo "Server is ready."
90
+ break
91
+ fi
92
+ sleep 0.1
93
+ done
94
+
95
+ # Run the client
96
+ echo ""
97
+ ruby "examples/$demo_dir/client.rb"
98
+ CLIENT_EXIT=$?
99
+
100
+ # Clean up
101
+ echo ""
102
+ echo "Stopping server..."
103
+ kill $SERVER_PID 2>/dev/null || true
104
+ wait $SERVER_PID 2>/dev/null || true
105
+
106
+ return $CLIENT_EXIT
107
+ }
108
+
109
+ # Main
110
+ case "${1:-}" in
111
+ --list | -l)
112
+ show_usage
113
+ ;;
114
+ --all | -a)
115
+ echo "Running all demos..."
116
+ echo
117
+ for i in {1..6}; do
118
+ run_demo $i
119
+ echo
120
+ done
121
+ echo "All demos completed!"
122
+ ;;
123
+ --help | -h | "")
124
+ show_usage
125
+ exit 0
126
+ ;;
127
+ *)
128
+ if [[ "$1" =~ ^[1-6]$ ]]; then
129
+ run_demo "$1"
130
+ else
131
+ echo "Error: Invalid argument '$1'"
132
+ echo
133
+ show_usage
134
+ exit 1
135
+ fi
136
+ ;;
137
+ esac