SunSec's picture
Add files using upload-large-folder tool
1f52d8e verified
from abc import ABC, abstractmethod
from typing import Optional
from pydantic import Field
from app.agent.base import BaseAgent
from app.llm import LLM
from app.schema import AgentState, Memory
class ReActAgent(BaseAgent, ABC):
name: str
description: Optional[str] = None
system_prompt: Optional[str] = None
next_step_prompt: Optional[str] = None
llm: Optional[LLM] = Field(default_factory=LLM)
memory: Memory = Field(default_factory=Memory)
state: AgentState = AgentState.IDLE
max_steps: int = 10
current_step: int = 0
@abstractmethod
async def think(self) -> bool: # think处理当前状态和决定下一个行为
"""Process current state and decide next action"""
@abstractmethod
async def act(self) -> str: # 指定决定的行为
"""Execute decided actions"""
async def step(self) -> str: # 一个单独的步骤,思考,然后执行
"""Execute a single step: think and act."""
should_act = await self.think()
if not should_act:
return "Thinking complete - no action needed"
return await self.act()