11# Interfaces
22
3- Multiple ways to interact with Agentic Forge: CLI for terminal users, WebSocket API for real-time applications , and Python SDK for direct integration.
3+ Multiple ways to interact with Agentic Forge: CLI for terminal users, SSE API for real-time streaming , and Python SDK for direct integration.
44
55## Interface Overview
66
77<div class =" diagram-container " >
88 <img src =" /diagrams/interfaces-overview.svg " alt =" Interface Overview " style =" max-width : 100% ; height : auto ;" />
99</div >
1010
11- ## Why WebSocket over REST?
11+ ## Why SSE over REST?
1212
1313REST's request-response model doesn't fit LLM agents well:
1414
15- | Challenge | REST Problem | WebSocket Solution |
16- | -----------| --------------| ------------------- |
15+ | Challenge | REST Problem | SSE Solution |
16+ | -----------| --------------| --------------|
1717| Streaming tokens | Wait for complete response | Stream as generated |
1818| Long-running tasks | Timeouts, no progress | Persistent connection |
19- | Stateful conversations | Resend full context | Session maintained |
20- | Cancel/feedback | Can't interrupt | Bi-directional messages |
19+ | Tool call progress | No visibility | Real-time events |
20+ | Heartbeats | Connection drops | Built-in ping events |
2121
2222## Recommended: SSE + REST Hybrid
2323
@@ -33,68 +33,52 @@ REST's request-response model doesn't fit LLM agents well:
3333| Completion events | Configuration |
3434| Heartbeat pings | Model/tool management |
3535
36- ## WebSocket Protocol
37-
38- ### Client → Server
39-
40- ``` json
41- // Send a chat message
42- {
43- "type" : " chat" ,
44- "payload" : {
45- "conversation_id" : " optional-id" ,
46- "message" : " Search for AI news" ,
47- "system_prompt" : " You are a research assistant" ,
48- "model" : " smart"
49- }
50- }
51-
52- // Cancel a request
53- {
54- "type" : " cancel" ,
55- "payload" : {
56- "conversation_id" : " conv-123"
57- }
58- }
36+ ## SSE Protocol
37+
38+ ### Client → Server (REST)
39+
40+ ``` bash
41+ # Create a conversation
42+ POST /conversations
43+ Content-Type: application/json
44+
45+ {" system_prompt" : " You are a research assistant" }
46+
47+ # Send a message
48+ POST /conversations/{id}/messages
49+ Content-Type: application/json
50+
51+ {" content" : " Search for AI news" }
52+
53+ # Cancel generation
54+ POST /conversations/{id}/cancel
55+ ```
56+
57+ ### Server → Client (SSE Stream)
58+
59+ Connect to ` GET /conversations/{id}/stream ` to receive events:
60+
5961```
62+ event: token
63+ data: {"token": "The", "cumulative": "The"}
64+
65+ event: thinking
66+ data: {"content": "Let me search for recent AI news..."}
67+
68+ event: tool_call
69+ data: {"id": "tc_1", "name": "web_search", "arguments": {"query": "AI news"}, "status": "pending"}
70+
71+ event: tool_call
72+ data: {"id": "tc_1", "name": "web_search", "status": "executing"}
73+
74+ event: tool_result
75+ data: {"id": "tc_1", "result": {...}}
76+
77+ event: complete
78+ data: {"usage": {"prompt_tokens": 150, "completion_tokens": 200}}
6079
61- ### Server → Client
62-
63- ``` json
64- // Token streaming
65- {
66- "type" : " token" ,
67- "conversation_id" : " conv-123" ,
68- "payload" : {
69- "token" : " The" ,
70- "cumulative" : " The"
71- }
72- }
73-
74- // Tool call event
75- {
76- "type" : " tool_call" ,
77- "conversation_id" : " conv-123" ,
78- "payload" : {
79- "tool_name" : " brave_search" ,
80- "arguments" : {"query" : " AI news 2025" },
81- "status" : " executing"
82- }
83- }
84-
85- // Completion
86- {
87- "type" : " complete" ,
88- "conversation_id" : " conv-123" ,
89- "payload" : {
90- "response" : " Here's what I found..." ,
91- "usage" : {
92- "prompt_tokens" : 150 ,
93- "completion_tokens" : 200 ,
94- "total_cost" : 0.003
95- }
96- }
97- }
80+ event: ping
81+ data: {}
9882```
9983
10084## Python SDK
@@ -150,7 +134,7 @@ agentic-forge run "Complex task" \
150134 --output json
151135
152136# Connect to remote orchestrator
153- agentic-forge chat --server ws ://localhost:8000/ws/chat
137+ agentic-forge chat --server http ://localhost:8001
154138```
155139
156140### Interactive Mode
@@ -187,42 +171,50 @@ REST API for managing the Armory:
187171
188172## Non-Python Integration
189173
190- For projects not written in Python, use the WebSocket API:
174+ For projects not written in Python, use the REST + SSE API:
191175
192176``` javascript
193177// JavaScript/TypeScript
194- const ws = new WebSocket (' ws://localhost:8000/ws/chat' );
195-
196- ws .onopen = () => {
197- ws .send (JSON .stringify ({
198- type: ' chat' ,
199- payload: { message: ' Search for AI news' }
200- }));
201- };
202-
203- ws .onmessage = (event ) => {
204- const data = JSON .parse (event .data );
205-
206- switch (data .type ) {
207- case ' token' :
208- process .stdout .write (data .payload .token );
209- break ;
210- case ' tool_call' :
211- console .log (` \n [${ data .payload .tool_name } ]` );
212- break ;
213- case ' complete' :
214- console .log (' \n Done!' );
215- break ;
216- }
217- };
178+ const baseUrl = ' http://localhost:8001' ;
179+
180+ // Create conversation and send message
181+ const conv = await fetch (` ${ baseUrl} /conversations` , {
182+ method: ' POST' ,
183+ headers: { ' Content-Type' : ' application/json' },
184+ body: JSON .stringify ({ system_prompt: ' You are a helpful assistant' })
185+ }).then (r => r .json ());
186+
187+ await fetch (` ${ baseUrl} /conversations/${ conv .id } /messages` , {
188+ method: ' POST' ,
189+ headers: { ' Content-Type' : ' application/json' },
190+ body: JSON .stringify ({ content: ' Search for AI news' })
191+ });
192+
193+ // Listen to SSE stream
194+ const eventSource = new EventSource (` ${ baseUrl} /conversations/${ conv .id } /stream` );
195+
196+ eventSource .addEventListener (' token' , (e ) => {
197+ const data = JSON .parse (e .data );
198+ process .stdout .write (data .token );
199+ });
200+
201+ eventSource .addEventListener (' tool_call' , (e ) => {
202+ const data = JSON .parse (e .data );
203+ console .log (` \n [${ data .name } : ${ data .status } ]` );
204+ });
205+
206+ eventSource .addEventListener (' complete' , () => {
207+ console .log (' \n Done!' );
208+ eventSource .close ();
209+ });
218210```
219211
220212## Summary
221213
222214| Interface | Use Case | Protocol |
223215| -----------| ----------| ----------|
224216| Python SDK | Python applications | Direct import |
225- | WebSocket API | Web/mobile, non-Python | WebSocket |
226- | SSE API | Simple streaming | HTTP + SSE |
217+ | SSE API | Web/mobile, real-time streaming | HTTP + SSE |
218+ | REST API | Management, CRUD operations | HTTP |
227219| CLI | Terminal users | Subprocess |
228220| Admin API | Armory management | REST |
0 commit comments