nat.plugins.langchain.agent.rewoo_agent.agent#
Attributes#
Classes#
State schema for the ReWOO Agent Graph |
|
Configurable ReWOO Agent. |
Module Contents#
- logger#
- class ReWOOPlanStep(/, **data: Any)#
Bases:
pydantic.BaseModel- evidence: ReWOOEvidence#
- class ReWOOGraphState(/, **data: Any)#
Bases:
pydantic.BaseModelState schema for the ReWOO Agent Graph
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.- task: langchain_core.messages.human.HumanMessage = None#
- plan: langchain_core.messages.ai.AIMessage = None#
- steps: langchain_core.messages.ai.AIMessage = None#
- evidence_map: dict[str, ReWOOPlanStep] = None#
- result: langchain_core.messages.ai.AIMessage = None#
- class ReWOOAgentGraph(
- llm: langchain_core.language_models.BaseChatModel,
- planner_prompt: langchain_core.prompts.chat.ChatPromptTemplate,
- solver_prompt: langchain_core.prompts.chat.ChatPromptTemplate,
- tools: list[langchain_core.tools.BaseTool],
- use_tool_schema: bool = True,
- callbacks: list[langchain_core.callbacks.base.AsyncCallbackHandler] | None = None,
- detailed_logs: bool = False,
- log_response_max_chars: int = 1000,
- tool_call_max_retries: int = 3,
- raise_tool_call_error: bool = True,
Bases:
nat.plugins.langchain.agent.base.BaseAgentConfigurable ReWOO Agent.
- Args:
detailed_logs: Toggles logging of inputs, outputs, and intermediate steps.
- planner_prompt#
- solver_prompt#
- tools_dict#
- tool_call_max_retries = 3#
- raise_tool_call_error = True#
- static _get_current_level_status(state: ReWOOGraphState) tuple[int, bool]#
Get the current execution level and whether it’s complete.
- Args:
state: The ReWOO graph state.
- Returns:
tuple of (current_level, is_complete). Level -1 means all execution is complete.
- static _parse_planner_output(planner_output: str) list[ReWOOPlanStep]#
- static _parse_planner_dependencies(
- steps: list[ReWOOPlanStep],
Parse planner steps to identify dependencies and create execution levels for parallel processing. This creates a dependency map and identifies which evidence placeholders can be executed in parallel.
- Args:
steps: list of plan steps from the planner.
- Returns:
A mapping from evidence placeholders to step info and execution levels for parallel processing.
- async planner_node(state: ReWOOGraphState)#
- async executor_node(state: ReWOOGraphState)#
Execute tools in parallel for the current dependency level.
This replaces the sequential execution with parallel execution of tools that have no dependencies between them.
- async _execute_single_tool(
- placeholder: str,
- step_info: ReWOOPlanStep,
- intermediate_results: dict[str, langchain_core.messages.tool.ToolMessage],
Execute a single tool with proper placeholder replacement.
- Args:
placeholder (str): The evidence placeholder (e.g., “#E1”). step_info (ReWOOPlanStep): Step information containing tool and tool_input. intermediate_results (dict[str, ToolMessage]): Current intermediate results for placeholder replacement.
- Returns:
ToolMessage with the tool execution result.
- async solver_node(state: ReWOOGraphState)#
- async conditional_edge(state: ReWOOGraphState)#
- async build_graph()#