Check the status and progress of a DeepCode task.
| 175 | |
| 176 | |
| 177 | class DeepCodeStatusTool(Tool): |
| 178 | """Check the status and progress of a DeepCode task.""" |
| 179 | |
| 180 | def __init__(self, api_url: str | None = None): |
| 181 | self._api_url = api_url or _get_deepcode_url() |
| 182 | |
| 183 | @property |
| 184 | def name(self) -> str: |
| 185 | return "deepcode_status" |
| 186 | |
| 187 | @property |
| 188 | def description(self) -> str: |
| 189 | return ( |
| 190 | "Check the status and progress of a DeepCode code generation task. " |
| 191 | "Provide the task_id returned by deepcode_paper2code or deepcode_chat2code. " |
| 192 | "Returns current status, progress percentage, and result when complete." |
| 193 | ) |
| 194 | |
| 195 | @property |
| 196 | def parameters(self) -> dict[str, Any]: |
| 197 | return { |
| 198 | "type": "object", |
| 199 | "properties": { |
| 200 | "task_id": { |
| 201 | "type": "string", |
| 202 | "description": "The task ID to check status for", |
| 203 | }, |
| 204 | }, |
| 205 | "required": ["task_id"], |
| 206 | } |
| 207 | |
| 208 | async def execute(self, task_id: str, **kwargs: Any) -> str: |
| 209 | try: |
| 210 | async with httpx.AsyncClient(timeout=15.0) as client: |
| 211 | response = await client.get(f"{self._api_url}/api/v1/workflows/status/{task_id}") |
| 212 | response.raise_for_status() |
| 213 | data = response.json() |
| 214 | |
| 215 | status = data.get("status", "unknown") |
| 216 | progress = data.get("progress", 0) |
| 217 | message = data.get("message", "") |
| 218 | result = data.get("result") |
| 219 | error = data.get("error") |
| 220 | |
| 221 | lines = [ |
| 222 | f"Task ID: {task_id}", |
| 223 | f"Status: {status}", |
| 224 | f"Progress: {progress}%", |
| 225 | ] |
| 226 | |
| 227 | if message: |
| 228 | lines.append(f"Message: {message}") |
| 229 | |
| 230 | if status == "completed" and result: |
| 231 | lines.append(f"\nResult:\n{result}") |
| 232 | elif status == "error" and error: |
| 233 | lines.append(f"\nError: {error}") |
| 234 | elif status == "waiting_for_input": |