Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property to conditionally set the LangGraph recursion limit #2074

Merged
merged 1 commit into from
Dec 15, 2024
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 @@ -10,5 +10,12 @@ public class LangGraphReactAgentWorkflow : AgentWorkflowBase
/// <inheritdoc/>
[JsonIgnore]
public override string Type => AgentWorkflowTypes.LangGraphReactAgent;

/// <summary>
/// When using LangGraph, the recursion limit sets the number of supersteps that the graph is allowed
/// to execute before it raises an error. The default value is 25. Set this value to null to use the default.
/// </summary>
[JsonPropertyName("graph_recursion_limit")]
public int? GraphRecursionLimit { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,11 @@ async def invoke_async(self, request: KnowledgeManagementCompletionRequest) -> C
graph = create_react_agent(llm, tools=tools, state_modifier=self.prompt.prefix)
messages = self._build_conversation_history_message_list(request.message_history, agent.conversation_history_settings.max_history)
messages.append(HumanMessage(content=request.user_prompt))
response = await graph.ainvoke({'messages': messages}, config={"configurable": {"original_user_prompt": request.user_prompt}})

response = await graph.ainvoke(
{'messages': messages},
config={"configurable": {"original_user_prompt": request.user_prompt, **({"recursion_limit": agent.workflow.graph_recursion_limit} if agent.workflow.graph_recursion_limit is not None else {})}}
)
# TODO: process tool messages with analysis results AIMessage with content='' but has addition_kwargs={'tool_calls';[...]}

# Get ContentArtifact items from ToolMessages
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Self, Literal
from pydantic import Field
from typing import Any, Self, Optional, Literal
from foundationallm.langchain.exceptions import LangChainException
from foundationallm.utils import object_utils
from .agent_workflow_base import AgentWorkflowBase
Expand All @@ -7,7 +8,8 @@ class LangGraphReactAgentWorkflow(AgentWorkflowBase):
"""
The configuration for a LangGraph ReAct agent workflow.
"""
type: Literal["langgraph-react-agent-workflow"] = "langgraph-react-agent-workflow"
type: Literal["langgraph-react-agent-workflow"] = "langgraph-react-agent-workflow"
graph_recursion_limit: Optional[int] = Field(None, alias="graph_recursion_limit")

@staticmethod
def from_object(obj: Any) -> Self:
Expand Down
Loading