Core agent engine of LoongFlow implementing the Reason-Act-Observe paradigm.
ReAct Agent Framework is the core intelligent agent engine in the LoongFlow project. It provides a highly modular component system for building AI agents with complex reasoning capabilities, solving tasks through multi-turn iterative execution.
The ReAct framework abstracts agent execution into four core components. Each component is defined as a Protocol interface, with default implementations provided out of the box.
- Reason - Analyze current context and decide next action
- Act - Execute tool calls based on reasoning output
- Observe - Process action results for next iteration
- Finalize - Determine task completion and construct final response
from agentsdk.message import Message
from agentsdk.models import LiteLLMModel
from agentsdk.tools import Toolkit
from evolux.react import ReActAgent
model = LiteLLMModel(
model_name="deepseek-r1",
base_url="http://your-llm-service/v1",
api_key="******"
)
# Create ReAct agent with default components
agent = ReActAgent.create_default(
model=model,
sys_prompt="You are a professional math problem solving assistant.",
toolkit=Toolkit(),
max_steps=10
)
result = await agent.run(Message.from_text("Solve the equation x^2 + 2x + 1 = 0"))from evolux.react import ReActAgent, AgentContext
from evolux.react.components import Reasoner
class CustomReasoner(Reasoner):
async def reason(self, context: AgentContext) -> Message:
# Your custom reasoning logic
pass
agent = ReActAgent(
context=agent_context,
reasoner=custom_reasoner,
actor=sequence_actor,
observer=default_observer,
finalizer=default_finalizer,
name="CustomAgent"
)Analyzes current context and decides on the next action.
Protocol:
class Reasoner(Protocol):
async def reason(self, context: AgentContext) -> Message:
"""Reason the current context and decide on the next action."""
...Default Implementation:
from evolux.react.components import DefaultReasoner
reasoner = DefaultReasoner(
model=llm_model,
system_prompt="Your system prompt"
)Executes the actions decided by the Reasoner (e.g., tool calls).
Protocol:
class Actor(Protocol):
async def act(
self, context: AgentContext, tool_calls: List[ToolCallElement]
) -> List[Message]:
"""Execute the actions decided by the Reasoner."""
...Default Implementations:
| Class | Description |
|---|---|
SequenceActor |
Execute tool calls sequentially |
ParallelActor |
Execute tool calls in parallel |
from evolux.react.components import SequenceActor, ParallelActor
actor = SequenceActor() # or ParallelActor()Processes action results and prepares them for the next reasoning step.
Protocol:
class Observer(Protocol):
async def observe(
self, context: AgentContext, tool_outputs: List[Message]
) -> Message | None:
"""Observe action results and prepare for next reasoning step."""
...Default Implementation:
from evolux.react.components import DefaultObserver
observer = DefaultObserver()Determines if the task is complete and constructs the final response.
Protocol:
class Finalizer(Protocol):
@property
def answer_schema(self) -> FunctionTool:
"""The schema of the special 'final answer' tool."""
...
async def resolve_answer(
self,
tool_call: ToolCallElement,
tool_output: ToolOutputElement,
) -> Message | None:
"""Resolve a tool interaction into the final answer."""
...
async def summarize_on_exceed(
self, context: AgentContext, **kwargs
) -> Message | None:
"""Summarize when react loop exceeds max_steps."""
...Default Implementation:
from evolux.react.components import DefaultFinalizer
finalizer = DefaultFinalizer(
model=llm_model,
summarize_prompt="Your summarization prompt",
output_schema=OutputModel # Optional
)Manages agent runtime state and resources:
from evolux.react import AgentContext
context = AgentContext(
memory=grade_memory,
toolkit=toolkit,
max_steps=10
)Customize execution flow at various stages:
supported_hook_types = [
"pre_run", "post_run",
"pre_reason", "post_reason",
"pre_act", "post_act",
"pre_observe", "post_observe"
]async def custom_interrupt_handler(context: AgentContext):
# Custom interrupt logic
pass
agent.register_interrupt(custom_interrupt_handler)Integrates with agentsdk's GradeMemory:
- Conversation history persistence
- Execution state tracking
- Experience accumulation
Seamlessly integrates with agentsdk tool system:
- Dynamic tool registration
- Parameter validation
- Error handling
src/evolux/react/
├── components/
│ ├── base.py # Protocol definitions
│ ├── default_reasoner.py
│ ├── default_actor.py
│ ├── default_observer.py
│ └── default_finalizer.py
├── context.py
├── react_agent_base.py
└── react_agent.py
ReAct framework serves as the core execution engine in LoongFlow:
- Planner Stage - Task analysis and plan generation
- Executor Stage - Solution optimization through execution
- Summary Stage - Experience summarization and memory updates
