|
36 | 36 | from camel.types.agents import ToolCallingRecord |
37 | 37 | from pydantic import BaseModel |
38 | 38 |
|
| 39 | +from app.component.environment import env |
39 | 40 | from app.service.task import ( |
40 | 41 | Action, |
41 | 42 | ActionActivateAgentData, |
|
52 | 53 | logger = logging.getLogger("agent") |
53 | 54 |
|
54 | 55 |
|
| 56 | +# Default 30 minutes; long agent turns (e.g. writing many chapters in one |
| 57 | +# run) can legitimately exceed it, so allow tuning without a rebuild. |
| 58 | +# A non-positive value disables the per-step timeout entirely. |
| 59 | +def default_step_timeout() -> float | None: |
| 60 | + raw = env("AGENT_STEP_TIMEOUT_SECONDS", "1800") |
| 61 | + try: |
| 62 | + value = float(raw) |
| 63 | + except (TypeError, ValueError): |
| 64 | + logger.warning( |
| 65 | + "Invalid AGENT_STEP_TIMEOUT_SECONDS value %r; using 1800", raw |
| 66 | + ) |
| 67 | + return 1800.0 |
| 68 | + return value if value > 0 else None |
| 69 | + |
| 70 | + |
55 | 71 | class ListenChatAgent(ChatAgent): |
56 | 72 | _cdp_clone_lock = ( |
57 | 73 | threading.Lock() |
@@ -95,12 +111,14 @@ def __init__( |
95 | 111 | pause_event: asyncio.Event | None = None, |
96 | 112 | prune_tool_calls_from_memory: bool = False, |
97 | 113 | enable_snapshot_clean: bool = False, |
98 | | - step_timeout: float | None = 1800, # 30 minutes |
| 114 | + step_timeout: float | None = None, |
99 | 115 | model_reload_callback: ( |
100 | 116 | Callable[[], BaseModelBackend | ModelManager] | None |
101 | 117 | ) = None, |
102 | 118 | **kwargs: Any, |
103 | 119 | ) -> None: |
| 120 | + if step_timeout is None: |
| 121 | + step_timeout = default_step_timeout() |
104 | 122 | super().__init__( |
105 | 123 | system_message=system_message, |
106 | 124 | model=model, |
|
0 commit comments