AgentNode#

Overview#

AgentNode is the agent node in EvoFabric, inheriting from AsyncStreamNode, and integrates memory management, tool calls, LLM calls, and input/output formatting. It is suitable for complex workflow scenarios requiring natural language interaction, state tracking, and tool operations.

Workflow:

  1. Call the memory module’s retrieval_update() to sequentially update the context state.

  2. Use the input_msg_format template to format the input state into messages recognizable by LLM.

  3. Call ChatClientBase to perform inference and obtain the preliminary response.

  4. Invoke the tool manager as needed to perform the relevant operations.

  5. Use the output_msg_format template to render the LLM response into the final output.

  6. Call the memory module’s add_messages() to update the memory in order.

Characteristics#

  • Integrated Memory Management: Can simultaneously manage multiple memory components, enabling context tracking.

  • Tool Call Support: Registered tools can be dynamically invoked during the reasoning process.

  • LLM Inference Encapsulation: Unified management of input formatting, inference parameters, and output rendering.

  • Streaming Output: Implemented via StreamWriter for step-by-step output of LLM responses.

  • Pydantic Output Validation: Supports output_schema for structured validation of LLM outputs.

Usage Instructions#

from pydantic import BaseModel
from evofabric.core.agent import AgentNode

class OutputSchema(BaseModel):
    name: str = "Alice"
    age: int = 32

agent_node = AgentNode(
    client=my_llm_client,
    system_prompt="You are an assistant.",
    tool_manager=[my_tool_manager],
    memory=[my_memory_component],
    output_schema=OutputSchema,
    input_msg_format="{{ state.query }}",
    output_msg_format="My name is {{ name }}, my age in {{ age }}"
)

...
graph.add_node("agent", agent_node)