(
self,
context: ContextWrapper[AstrAgentContext],
code: str,
silent: bool = False,
timeout: int = 30,
)
| 82 | parameters: dict = field(default_factory=lambda: param_schema) |
| 83 | |
| 84 | async def call( |
| 85 | self, |
| 86 | context: ContextWrapper[AstrAgentContext], |
| 87 | code: str, |
| 88 | silent: bool = False, |
| 89 | timeout: int = 30, |
| 90 | ) -> ToolExecResult: |
| 91 | if permission_error := check_admin_permission(context, "Python execution"): |
| 92 | return permission_error |
| 93 | sb = await get_booter( |
| 94 | context.context.context, |
| 95 | context.context.event.unified_msg_origin, |
| 96 | ) |
| 97 | effective_timeout = ( |
| 98 | min(timeout, context.tool_call_timeout) |
| 99 | if timeout > 0 |
| 100 | else context.tool_call_timeout |
| 101 | ) |
| 102 | try: |
| 103 | result = await sb.python.exec( |
| 104 | code, |
| 105 | timeout=effective_timeout, |
| 106 | silent=silent, |
| 107 | ) |
| 108 | return await handle_result(result, context.context.event) |
| 109 | except Exception as e: |
| 110 | return f"Error executing code: {str(e)}" |
| 111 | |
| 112 | |
| 113 | @builtin_tool(config=_LOCAL_PYTHON_TOOL_CONFIG) |
nothing calls this directly
no test coverage detected