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:
Call the memory module’s
retrieval_update()to sequentially update the context state.Use the
input_msg_formattemplate to format the input state into messages recognizable by LLM.Call
ChatClientBaseto perform inference and obtain the preliminary response.Invoke the tool manager as needed to perform the relevant operations.
Use the
output_msg_formattemplate to render the LLM response into the final output.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
StreamWriterfor step-by-step output of LLM responses.Pydantic Output Validation: Supports
output_schemafor 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)