Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ToolCallArgsEvent,
ToolCallEndEvent,
ToolCallStartEvent,
ToolCallResultEvent,
ThinkingTextMessageStartEvent,
ThinkingTextMessageContentEvent,
ThinkingTextMessageEndEvent,
Expand Down Expand Up @@ -674,31 +675,40 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
)

elif event_type == LangGraphEventTypes.OnToolEnd:
if self.active_run["has_function_streaming"]:
return
tool_call_output = event["data"]["output"]
yield self._dispatch_event(
ToolCallStartEvent(
type=EventType.TOOL_CALL_START,
tool_call_id=tool_call_output.tool_call_id,
tool_call_name=tool_call_output.name,
parent_message_id=tool_call_output.id,
raw_event=event,
if not self.active_run["has_function_streaming"]:
yield self._dispatch_event(
ToolCallStartEvent(
type=EventType.TOOL_CALL_START,
tool_call_id=tool_call_output.tool_call_id,
tool_call_name=tool_call_output.name,
parent_message_id=tool_call_output.id,
raw_event=event,
)
)
)
yield self._dispatch_event(
ToolCallArgsEvent(
type=EventType.TOOL_CALL_ARGS,
tool_call_id=tool_call_output.tool_call_id,
delta=json.dumps(event["data"]["input"]),
raw_event=event
yield self._dispatch_event(
ToolCallArgsEvent(
type=EventType.TOOL_CALL_ARGS,
tool_call_id=tool_call_output.tool_call_id,
delta=json.dumps(event["data"]["input"]),
raw_event=event
)
)
)
yield self._dispatch_event(
ToolCallEndEvent(
type=EventType.TOOL_CALL_END,
tool_call_id=tool_call_output.tool_call_id,
raw_event=event
)
)

yield self._dispatch_event(
ToolCallEndEvent(
type=EventType.TOOL_CALL_END,
ToolCallResultEvent(
type=EventType.TOOL_CALL_RESULT,
tool_call_id=tool_call_output.tool_call_id,
raw_event=event
message_id=uuid.uuid4(),
content=tool_call_output.content,
role="tool"
)
)

Expand Down
46 changes: 28 additions & 18 deletions typescript-sdk/integrations/langgraph/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ import {
ToolCallArgsEvent,
ToolCallEndEvent,
ToolCallStartEvent,
ToolCallResultEvent,
ThinkingTextMessageStartEvent,
ThinkingTextMessageContentEvent,
ThinkingTextMessageEndEvent,
ThinkingStartEvent,
ThinkingEndEvent,
Message as AGUIMessage,
} from "@ag-ui/client";
import { RunsStreamPayload } from "@langchain/langgraph-sdk/dist/types";
import {
Expand All @@ -76,6 +76,7 @@ export type ProcessedEvents =
| ToolCallStartEvent
| ToolCallArgsEvent
| ToolCallEndEvent
| ToolCallResultEvent
| ThinkingStartEvent
| ThinkingEndEvent
| StateSnapshotEvent
Expand Down Expand Up @@ -774,26 +775,35 @@ export class LangGraphAgent extends AbstractAgent {
});
break;
case LangGraphEventTypes.OnToolEnd:
if (this.activeRun!.hasFunctionStreaming) break;
const toolCallOutput = event.data.output
const toolCallOutput = event.data?.output
if (!this.activeRun!.hasFunctionStreaming) {
this.dispatchEvent({
type: EventType.TOOL_CALL_START,
toolCallId: toolCallOutput.tool_call_id,
toolCallName: toolCallOutput.name,
parentMessageId: toolCallOutput.id,
rawEvent: event,
})
this.dispatchEvent({
type: EventType.TOOL_CALL_ARGS,
toolCallId: toolCallOutput.tool_call_id,
delta: JSON.stringify(event.data.input),
rawEvent: event,
});
this.dispatchEvent({
type: EventType.TOOL_CALL_END,
toolCallId: toolCallOutput.tool_call_id,
rawEvent: event,
});
}
this.dispatchEvent({
type: EventType.TOOL_CALL_START,
type: EventType.TOOL_CALL_RESULT,
toolCallId: toolCallOutput.tool_call_id,
toolCallName: toolCallOutput.name,
parentMessageId: toolCallOutput.id,
rawEvent: event,
content: toolCallOutput?.content,
messageId: randomUUID(),
role: "tool",
})
this.dispatchEvent({
type: EventType.TOOL_CALL_ARGS,
toolCallId: toolCallOutput.tool_call_id,
delta: JSON.stringify(event.data.input),
rawEvent: event,
});
this.dispatchEvent({
type: EventType.TOOL_CALL_END,
toolCallId: toolCallOutput.tool_call_id,
rawEvent: event,
});
break;
}
}

Expand Down
Loading