Skip to content

Commit 3004a63

Browse files
committed
add result
1 parent d4e7568 commit 3004a63

File tree

8 files changed

+52
-34
lines changed

8 files changed

+52
-34
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/sdk/js/core/events.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ type RunFinishedEvent = BaseEvent & {
8585
type: EventType.RUN_FINISHED
8686
threadId: string
8787
runId: string
88+
result?: any
8889
}
8990
```
9091
91-
| Property | Type | Description |
92-
| ---------- | -------- | ----------------------------- |
93-
| `threadId` | `string` | ID of the conversation thread |
94-
| `runId` | `string` | ID of the agent run |
92+
| Property | Type | Description |
93+
| ---------- | ---------------- | ------------------------------ |
94+
| `threadId` | `string` | ID of the conversation thread |
95+
| `runId` | `string` | ID of the agent run |
96+
| `result` | `any` (optional) | Result data from the agent run |
9597
9698
### RunErrorEvent
9799

docs/sdk/python/core/events.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ class RunFinishedEvent(BaseEvent):
9191
type: Literal[EventType.RUN_FINISHED]
9292
thread_id: str
9393
run_id: str
94+
result: Optional[Any] = None
9495
```
9596

96-
| Property | Type | Description |
97-
| ----------- | ----- | ----------------------------- |
98-
| `thread_id` | `str` | ID of the conversation thread |
99-
| `run_id` | `str` | ID of the agent run |
97+
| Property | Type | Description |
98+
| ----------- | --------------- | ------------------------------ |
99+
| `thread_id` | `str` | ID of the conversation thread |
100+
| `run_id` | `str` | ID of the agent run |
101+
| `result` | `Optional[Any]` | Result data from the agent run |
100102

101103
### RunErrorEvent
102104

python-sdk/ag_ui/core/events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class RunFinishedEvent(BaseEvent):
226226
type: Literal[EventType.RUN_FINISHED]
227227
thread_id: str
228228
run_id: str
229+
result: Optional[Any] = None
229230

230231

231232
class RunErrorEvent(BaseEvent):

typescript-sdk/packages/client/src/agent/agent.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ export abstract class AbstractAgent {
5656
): Promise<void> {
5757
this.agentId = this.agentId ?? uuidv4();
5858
const input = this.prepareRunAgentInput(parameters);
59-
const subscribers = [...this.subscribers, subscriber ?? {}];
59+
let result: any = undefined;
60+
const subscribers: RunAgentSubscriber[] = [
61+
{
62+
onRunFinishedEvent: (params) => {
63+
result = params.result;
64+
},
65+
},
66+
...this.subscribers,
67+
subscriber ?? {},
68+
];
6069

6170
await this.onInitialize(input, subscribers);
6271

@@ -74,7 +83,7 @@ export abstract class AbstractAgent {
7483
}),
7584
);
7685

77-
return lastValueFrom(pipeline(of(null))).then(() => {});
86+
return lastValueFrom(pipeline(of(null))).then(() => result);
7887
}
7988

8089
public abortRun() {}

typescript-sdk/packages/client/src/agent/subscriber.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,91 +44,91 @@ export interface RunAgentSubscriber {
4444
// Request lifecycle
4545
onRunInitialized?(
4646
params: RunAgentSubscriberParams,
47-
): MaybePromise<Omit<AgentStateMutation, "stopPropagation"> | undefined>;
47+
): MaybePromise<Omit<AgentStateMutation, "stopPropagation"> | void>;
4848
onRunFailed?(
4949
params: { error: Error } & RunAgentSubscriberParams,
50-
): MaybePromise<Omit<AgentStateMutation, "stopPropagation"> | undefined>;
50+
): MaybePromise<Omit<AgentStateMutation, "stopPropagation"> | void>;
5151
onRunFinalized?(
5252
params: RunAgentSubscriberParams,
53-
): MaybePromise<Omit<AgentStateMutation, "stopPropagation"> | undefined>;
53+
): MaybePromise<Omit<AgentStateMutation, "stopPropagation"> | void>;
5454

5555
// Events
5656
onEvent?(
5757
params: { event: BaseEvent } & RunAgentSubscriberParams,
58-
): MaybePromise<AgentStateMutation | undefined>;
58+
): MaybePromise<AgentStateMutation | void>;
5959

6060
onRunStartedEvent?(
6161
params: { event: RunStartedEvent } & RunAgentSubscriberParams,
62-
): MaybePromise<AgentStateMutation | undefined>;
62+
): MaybePromise<AgentStateMutation | void>;
6363
onRunFinishedEvent?(
64-
params: { event: RunFinishedEvent } & RunAgentSubscriberParams,
65-
): MaybePromise<AgentStateMutation | undefined>;
64+
params: { event: RunFinishedEvent; result?: any } & RunAgentSubscriberParams,
65+
): MaybePromise<AgentStateMutation | void>;
6666
onRunErrorEvent?(
6767
params: { event: RunErrorEvent } & RunAgentSubscriberParams,
68-
): MaybePromise<AgentStateMutation | undefined>;
68+
): MaybePromise<AgentStateMutation | void>;
6969

7070
onStepStartedEvent?(
7171
params: { event: StepStartedEvent } & RunAgentSubscriberParams,
72-
): MaybePromise<AgentStateMutation | undefined>;
72+
): MaybePromise<AgentStateMutation | void>;
7373
onStepFinishedEvent?(
7474
params: { event: StepFinishedEvent } & RunAgentSubscriberParams,
75-
): MaybePromise<AgentStateMutation | undefined>;
75+
): MaybePromise<AgentStateMutation | void>;
7676

7777
onTextMessageStartEvent?(
7878
params: { event: TextMessageStartEvent } & RunAgentSubscriberParams,
79-
): MaybePromise<AgentStateMutation | undefined>;
79+
): MaybePromise<AgentStateMutation | void>;
8080
onTextMessageContentEvent?(
8181
params: {
8282
event: TextMessageContentEvent;
8383
textMessageBuffer: string;
8484
} & RunAgentSubscriberParams,
85-
): MaybePromise<AgentStateMutation | undefined>;
85+
): MaybePromise<AgentStateMutation | void>;
8686
onTextMessageEndEvent?(
8787
params: { event: TextMessageEndEvent; textMessageBuffer: string } & RunAgentSubscriberParams,
88-
): MaybePromise<AgentStateMutation | undefined>;
88+
): MaybePromise<AgentStateMutation | void>;
8989

9090
onToolCallStartEvent?(
9191
params: { event: ToolCallStartEvent } & RunAgentSubscriberParams,
92-
): MaybePromise<AgentStateMutation | undefined>;
92+
): MaybePromise<AgentStateMutation | void>;
9393
onToolCallArgsEvent?(
9494
params: {
9595
event: ToolCallArgsEvent;
9696
toolCallBuffer: string;
9797
toolCallName: string;
9898
partialToolCallArgs: Record<string, any>;
9999
} & RunAgentSubscriberParams,
100-
): MaybePromise<AgentStateMutation | undefined>;
100+
): MaybePromise<AgentStateMutation | void>;
101101
onToolCallEndEvent?(
102102
params: {
103103
event: ToolCallEndEvent;
104104
toolCallName: string;
105105
toolCallArgs: Record<string, any>;
106106
} & RunAgentSubscriberParams,
107-
): MaybePromise<AgentStateMutation | undefined>;
107+
): MaybePromise<AgentStateMutation | void>;
108108

109109
onToolCallResultEvent?(
110110
params: { event: ToolCallResultEvent } & RunAgentSubscriberParams,
111-
): MaybePromise<AgentStateMutation | undefined>;
111+
): MaybePromise<AgentStateMutation | void>;
112112

113113
onStateSnapshotEvent?(
114114
params: { event: StateSnapshotEvent } & RunAgentSubscriberParams,
115-
): MaybePromise<AgentStateMutation | undefined>;
115+
): MaybePromise<AgentStateMutation | void>;
116116

117117
onStateDeltaEvent?(
118118
params: { event: StateDeltaEvent } & RunAgentSubscriberParams,
119-
): MaybePromise<AgentStateMutation | undefined>;
119+
): MaybePromise<AgentStateMutation | void>;
120120

121121
onMessagesSnapshotEvent?(
122122
params: { event: MessagesSnapshotEvent } & RunAgentSubscriberParams,
123-
): MaybePromise<AgentStateMutation | undefined>;
123+
): MaybePromise<AgentStateMutation | void>;
124124

125125
onRawEvent?(
126126
params: { event: RawEvent } & RunAgentSubscriberParams,
127-
): MaybePromise<AgentStateMutation | undefined>;
127+
): MaybePromise<AgentStateMutation | void>;
128128

129129
onCustomEvent?(
130130
params: { event: CustomEvent } & RunAgentSubscriberParams,
131-
): MaybePromise<AgentStateMutation | undefined>;
131+
): MaybePromise<AgentStateMutation | void>;
132132

133133
// State changes
134134
onMessagesChanged?(params: Omit<RunAgentSubscriberParams, "state">): MaybePromise<void>;
@@ -143,7 +143,7 @@ export async function runSubscribersWithMutation(
143143
subscriber: RunAgentSubscriber,
144144
messages: Message[],
145145
state: State,
146-
) => MaybePromise<AgentStateMutation | undefined>,
146+
) => MaybePromise<AgentStateMutation | void>,
147147
): Promise<AgentStateMutation> {
148148
let messages: Message[] = initialMessages;
149149
let state: State = initialState;

typescript-sdk/packages/client/src/apply/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ export const defaultApplyEvents = (
488488
state,
489489
agent,
490490
input,
491+
result: (event as RunFinishedEvent).result,
491492
}),
492493
);
493494
applyMutation(mutation);

typescript-sdk/packages/proto/src/proto/events.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ message RunFinishedEvent {
103103
BaseEvent base_event = 1;
104104
string thread_id = 2;
105105
string run_id = 3;
106+
optional google.protobuf.Value result = 4;
106107
}
107108

108109
message RunErrorEvent {

0 commit comments

Comments
 (0)