Run the agent to complete a task. Args: task: Natural language description of the task. Returns: Final message from the agent.
(self, task: str)
| 82 | self._step_count = 0 |
| 83 | |
| 84 | def run(self, task: str) -> str: |
| 85 | """ |
| 86 | Run the agent to complete a task. |
| 87 | |
| 88 | Args: |
| 89 | task: Natural language description of the task. |
| 90 | |
| 91 | Returns: |
| 92 | Final message from the agent. |
| 93 | """ |
| 94 | self._context = [] |
| 95 | self._step_count = 0 |
| 96 | |
| 97 | # First step with user prompt |
| 98 | result = self._execute_step(task, is_first=True) |
| 99 | |
| 100 | if result.finished: |
| 101 | return result.message or "Task completed" |
| 102 | |
| 103 | # Continue until finished or max steps reached |
| 104 | while self._step_count < self.agent_config.max_steps: |
| 105 | result = self._execute_step(is_first=False) |
| 106 | |
| 107 | if result.finished: |
| 108 | return result.message or "Task completed" |
| 109 | |
| 110 | return "Max steps reached" |
| 111 | |
| 112 | def step(self, task: str | None = None) -> StepResult: |
| 113 | """ |
no test coverage detected