Skip to content

Commit 3986f5a

Browse files
feat: add AgentConfig top lvl for create_react_agent
1 parent af09bef commit 3986f5a

7 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/uipath_langchain/agent/react/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""UiPath ReAct Agent implementation"""
22

33
from .agent import create_agent
4-
from .state import AgentGraphNode, AgentGraphState
4+
from .types import AgentGraphNode, AgentGraphState
55
from .utils import resolve_output_model
66

77
__all__ = [

src/uipath_langchain/agent/react/agent.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from .router import (
1919
route_agent,
2020
)
21-
from .state import AgentGraphNode, AgentGraphState
2221
from .terminate_node import (
2322
create_terminate_node,
2423
)
2524
from .tools import create_flow_control_tools
25+
from .types import AgentGraphConfig, AgentGraphNode, AgentGraphState
2626

2727

2828
def create_agent(
@@ -32,13 +32,16 @@ def create_agent(
3232
*,
3333
state_schema: Type[AgentGraphState] = AgentGraphState,
3434
response_format: type[BaseModel] | None = None,
35-
recursion_limit: int = 50,
35+
config: AgentGraphConfig | None = None,
3636
) -> StateGraph[AgentGraphState]:
3737
"""Build agent graph with INIT -> AGENT <-> TOOLS loop, terminated by control flow tools.
3838
3939
Control flow tools (end_execution, raise_error) are auto-injected alongside regular tools.
4040
"""
41-
os.environ["LANGCHAIN_RECURSION_LIMIT"] = str(recursion_limit)
41+
if config is None:
42+
config = AgentGraphConfig()
43+
44+
os.environ["LANGCHAIN_RECURSION_LIMIT"] = str(config.recursion_limit)
4245

4346
agent_tools = list(tools)
4447
flow_control_tools: list[BaseTool] = create_flow_control_tools(response_format)

src/uipath_langchain/agent/react/init_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from langchain_core.messages import HumanMessage, SystemMessage
66

7-
from .state import AgentGraphState
7+
from .types import AgentGraphState
88

99

1010
def create_init_node(

src/uipath_langchain/agent/react/llm_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from langchain_core.tools import BaseTool
88

99
from .constants import MAX_SUCCESSIVE_COMPLETIONS
10-
from .state import AgentGraphState
10+
from .types import AgentGraphState
1111
from .utils import count_successive_completions
1212

1313

src/uipath_langchain/agent/react/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .constants import MAX_SUCCESSIVE_COMPLETIONS
99
from .exceptions import AgentNodeRoutingException
10-
from .state import AgentGraphNode, AgentGraphState
10+
from .types import AgentGraphNode, AgentGraphState
1111
from .utils import count_successive_completions
1212

1313
FLOW_CONTROL_TOOLS = [END_EXECUTION_TOOL.name, RAISE_ERROR_TOOL.name]

src/uipath_langchain/agent/react/terminate_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
AgentNodeRoutingException,
1212
AgentTerminationException,
1313
)
14-
from .state import AgentGraphState
14+
from .types import AgentGraphState
1515

1616

1717
def create_terminate_node(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import StrEnum
44

55
from langgraph.graph import MessagesState
6+
from pydantic import BaseModel, Field
67

78

89
class AgentGraphState(MessagesState):
@@ -16,3 +17,9 @@ class AgentGraphNode(StrEnum):
1617
AGENT = "agent"
1718
TOOLS = "tools"
1819
TERMINATE = "terminate"
20+
21+
22+
class AgentGraphConfig(BaseModel):
23+
recursion_limit: int = Field(
24+
default=50, ge=1, description="Maximum recursion limit for the agent graph"
25+
)

0 commit comments

Comments
 (0)