Run the agent to complete a task. Args: task: Natural language description of the task. Returns: Final message from the agent.
(self, task: str)
| 100 | self._step_count = 0 |
| 101 | |
| 102 | def run(self, task: str) -> str: |
| 103 | """ |
| 104 | Run the agent to complete a task. |
| 105 | |
| 106 | Args: |
| 107 | task: Natural language description of the task. |
| 108 | |
| 109 | Returns: |
| 110 | Final message from the agent. |
| 111 | """ |
| 112 | self._context = [] |
| 113 | self._step_count = 0 |
| 114 | |
| 115 | # First step with user prompt |
| 116 | result = self._execute_step(task, is_first=True) |
| 117 | |
| 118 | if result.finished: |
| 119 | return result.message or "Task completed" |
| 120 | |
| 121 | # Continue until finished or max steps reached |
| 122 | while self._step_count < self.agent_config.max_steps: |
| 123 | result = self._execute_step(is_first=False) |
| 124 | |
| 125 | if result.finished: |
| 126 | return result.message or "Task completed" |
| 127 | |
| 128 | return "Max steps reached" |
| 129 | |
| 130 | def step(self, task: str | None = None) -> StepResult: |
| 131 | """ |