Skip to content

Commit db77f63

Browse files
authored
Client API (#147)
Implement interfaces to use AG-UI client side.
1 parent 0a4057a commit db77f63

34 files changed

+4795
-515
lines changed

docs/concepts/events.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ The `RunFinished` event indicates that an agent has successfully completed all
9595
its work for the current run. Upon receiving this event, frontends should
9696
finalize any UI states that were waiting on the agent's completion. This event
9797
marks a clean termination point and indicates that no further processing will
98-
occur in this run unless explicitly requested.
98+
occur in this run unless explicitly requested. The optional `result` field can
99+
contain any output data produced by the agent run.
99100

100101
| Property | Description |
101102
| ---------- | ----------------------------- |
102103
| `threadId` | ID of the conversation thread |
103104
| `runId` | ID of the agent run |
105+
| `result` | Optional result data from run |
104106

105107
### RunError
106108

docs/docs.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@
6868
},
6969
{
7070
"group": "@ag-ui/client",
71-
"pages": ["sdk/js/client/overview"]
71+
"pages": [
72+
"sdk/js/client/overview",
73+
"sdk/js/client/abstract-agent",
74+
"sdk/js/client/http-agent",
75+
"sdk/js/client/subscriber"
76+
]
7277
},
7378
"sdk/js/encoder",
7479
"sdk/js/proto"

docs/sdk/js/client/abstract-agent.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class MyAgent extends AbstractAgent {
5353

5454
### runAgent()
5555

56-
The primary method for executing an agent and receiving the event stream.
56+
The primary method for executing an agent and processing the result.
5757

5858
```typescript
59-
runAgent(parameters?: RunAgentParameters): Observable<RuntimeProtocolEvent>
59+
runAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>
6060
```
6161

6262
#### Parameters
@@ -70,6 +70,31 @@ interface RunAgentParameters {
7070
}
7171
```
7272

73+
The optional `subscriber` parameter allows you to provide an
74+
[AgentSubscriber](/sdk/js/client/subscriber) for handling events during this
75+
specific run.
76+
77+
#### Return Value
78+
79+
```typescript
80+
interface RunAgentResult {
81+
result: any // The final result returned by the agent
82+
newMessages: Message[] // New messages added during this run
83+
}
84+
```
85+
86+
### subscribe()
87+
88+
Adds an [AgentSubscriber](/sdk/js/client/subscriber) to handle events across
89+
multiple agent runs.
90+
91+
```typescript
92+
subscribe(subscriber: AgentSubscriber): { unsubscribe: () => void }
93+
```
94+
95+
Returns an object with an `unsubscribe()` method to remove the subscriber when
96+
no longer needed.
97+
7398
### abortRun()
7499

75100
Cancels the current agent execution.

docs/sdk/js/client/http-agent.mdx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,40 @@ const agent = new HttpAgent({
3939

4040
### runAgent()
4141

42-
Executes the agent by making an HTTP request to the configured endpoint. Returns
43-
an observable event stream.
42+
Executes the agent by making an HTTP request to the configured endpoint.
4443

4544
```typescript
46-
runAgent(parameters?: RunHttpAgentConfig): Observable<RuntimeProtocolEvent>
45+
runAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>
4746
```
4847

4948
#### Parameters
5049

50+
The `parameters` argument follows the standard `RunAgentParameters` interface.
51+
The optional `subscriber` parameter allows you to provide an
52+
[AgentSubscriber](/sdk/js/client/subscriber) for handling events during this
53+
specific run.
54+
55+
#### Return Value
56+
5157
```typescript
52-
interface RunHttpAgentConfig extends RunAgentParameters {
53-
abortController?: AbortController // For canceling the HTTP request
58+
interface RunAgentResult {
59+
result: any // The final result returned by the agent
60+
newMessages: Message[] // New messages added during this run
5461
}
5562
```
5663

64+
### subscribe()
65+
66+
Adds an [AgentSubscriber](/sdk/js/client/subscriber) to handle events across
67+
multiple agent runs.
68+
69+
```typescript
70+
subscribe(subscriber: AgentSubscriber): { unsubscribe: () => void }
71+
```
72+
73+
Returns an object with an `unsubscribe()` method to remove the subscriber when
74+
no longer needed.
75+
5776
### abortRun()
5877

5978
Cancels the current HTTP request using the AbortController.

docs/sdk/js/client/overview.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,28 @@ Concrete implementation for HTTP-based agent connectivity:
6060
Ready-to-use HTTP implementation for agent connectivity, using a highly
6161
efficient event encoding format
6262
</Card>
63+
64+
## AgentSubscriber
65+
66+
Event-driven subscriber system for handling agent lifecycle events and state
67+
mutations during agent execution:
68+
69+
- [Event Handlers](/sdk/js/client/subscriber#event-handlers) - Lifecycle,
70+
message, tool call, and state events
71+
- [State Management](/sdk/js/client/subscriber#state-management) - Mutation
72+
control and propagation handling
73+
- [Usage Examples](/sdk/js/client/subscriber#usage-examples) - Logging,
74+
persistence, and error handling patterns
75+
- [Integration](/sdk/js/client/subscriber#integration-with-agents) - Registering
76+
and using subscribers with agents
77+
78+
<Card
79+
title="AgentSubscriber Reference"
80+
icon="bolt"
81+
href="/sdk/js/client/subscriber"
82+
color="#3B82F6"
83+
iconType="solid"
84+
>
85+
Comprehensive event system for reactive agent interaction and middleware-style
86+
functionality
87+
</Card>

0 commit comments

Comments
 (0)