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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ langchain-experimental = ">=0.0.11"
langchain-google-genai = ">=2.1.9"
langchain-openai = ">=0.0.1"
langgraph = "^0.6.1"
ag-ui-langgraph = { version = "0.0.12a3", extras = ["fastapi"] }
ag-ui-langgraph = { version = "0.0.14a0", extras = ["fastapi"] }
python-dotenv = "^1.0.0"
fastapi = "^0.115.12"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,26 @@ def langgraph_default_merge_state(self, state: State, messages: List[BaseMessage
else:
tools_as_dicts.append(tool)

all_tools = [*state.get("tools", []), *tools_as_dicts]

# Remove duplicates based on tool name
seen_names = set()
unique_tools = []
for tool in all_tools:
tool_name = tool.get("name") if isinstance(tool, dict) else getattr(tool, "name", None)
if tool_name and tool_name not in seen_names:
seen_names.add(tool_name)
unique_tools.append(tool)
elif not tool_name:
# Keep tools without names (shouldn't happen, but just in case)
unique_tools.append(tool)

return {
**state,
"messages": new_messages,
"tools": [*state.get("tools", []), *tools_as_dicts],
"tools": unique_tools,
"ag-ui": {
"tools": [*state.get("tools", []), *tools_as_dicts],
"tools": unique_tools,
"context": input.context or []
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ag-ui-langgraph"
version = "0.0.13"
version = "0.0.14-alpha.0"
description = "Implementation of the AG-UI protocol for LangGraph."
authors = ["Ran Shem Tov <[email protected]>"]
readme = "README.md"
Expand Down
32 changes: 18 additions & 14 deletions typescript-sdk/integrations/langgraph/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
PredictStateTool,
LangGraphReasoning,
StateEnrichment,
LangGraphTool,
LangGraphToolWithName,
} from "./types";
import {
AbstractAgent,
Expand Down Expand Up @@ -1003,21 +1003,25 @@ export class LangGraphAgent extends AbstractAgent {

const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));

const langGraphTools: LangGraphTool[] = [...(state.tools ?? []), ...(input.tools ?? [])].map((tool) => {
if (tool.type) {
return tool;
const langGraphTools: LangGraphToolWithName[] = [...(state.tools ?? []), ...(input.tools ?? [])].reduce((acc, tool) => {
let mappedTool = tool;
if (!tool.type) {
mappedTool = {
type: "function",
name: tool.name,
function: {
name: tool.name,
description: tool.description,
parameters: tool.parameters,
},
}
}

return {
type: "function",
name: tool.name,
function: {
name: tool.name,
description: tool.description,
parameters: tool.parameters,
},
};
});
// Verify no duplicated
if (acc.find((t: LangGraphToolWithName) => (t.name === mappedTool.name) || t.function.name === mappedTool.function.name)) return acc;

return [...acc, mappedTool];
}, []);

return {
...state,
Expand Down
7 changes: 4 additions & 3 deletions typescript-sdk/integrations/langgraph/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export enum LangGraphEventTypes {
OnInterrupt = "on_interrupt",
}

export type LangGraphTool = {
export type LangGraphToolWithName = {
type: "function";
name?: string;
function: {
name: string;
description: string;
Expand All @@ -29,9 +30,9 @@ export type State<TDefinedState = Record<string, any>> = {
} & Record<string, any>;
export interface StateEnrichment {
messages: LangGraphMessage[];
tools: LangGraphTool[];
tools: LangGraphToolWithName[];
'ag-ui': {
tools: LangGraphTool[];
tools: LangGraphToolWithName[];
context: RunAgentInput['context']
}
}
Expand Down
Loading