{"record":{"id":"98eb5d104dea7541","repo":"FoundationAgents/OpenManus","slug":"error-invoking-agent-e","errorCode":null,"errorMessage":"Error invoking agent: {e}","messagePattern":"Error invoking agent: (.+?)","errorType":"exception","errorClass":"ServerError","httpStatus":null,"severity":"error","filePath":"protocol/a2a/app/agent_executor.py","lineNumber":45,"sourceCode":"        self.agent_factory = agent_factory\n\n    async def execute(\n        self,\n        context: RequestContext,\n        event_queue: EventQueue,\n    ) -> None:\n        error = self._validate_request(context)\n        if error:\n            raise ServerError(error=InvalidParamsError())\n\n        query = context.get_user_input()\n        try:\n            self.agent = await self.agent_factory()\n            result = await self.agent.invoke(query, context.context_id)\n            print(f\"Final Result ===> {result}\")\n        except Exception as e:\n            print(\"Error invoking agent: %s\", e)\n            raise ServerError(error=ValueError(f\"Error invoking agent: {e}\")) from e\n        parts = [\n            Part(\n                root=TextPart(\n                    text=(\n                        result[\"content\"]\n                        if result[\"content\"]\n                        else \"failed to generate response\"\n                    )\n                ),\n            )\n        ]\n        event_queue.enqueue_event(\n            completed_task(\n                context.task_id,\n                context.context_id,\n                [new_artifact(parts, f\"task_{context.task_id}\")],\n                [context.message],\n            )","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/protocol/a2a/app/agent_executor.py#L27-L63","documentation":"Raised by the A2A agent executor when constructing or invoking the agent fails: any exception from agent_factory() or agent.invoke() (including the NotImplementedError from stream-based misuse, network errors to backing LLMs, missing API keys, or agent timeouts) is wrapped in ServerError(ValueError('Error invoking agent: ...')). The original exception is chained via 'from e'.","triggerScenarios":"agent_factory() raising (bad config, missing env vars like API keys, dependency import errors), or agent.invoke() raising mid-run (LLM provider error, tool failure inside Manus, invalid session/context). The printed line uses %s inside print(), which is a formatting bug — the raw '%s' placeholder and exception print literally, so logs look odd.","commonSituations":"Missing or expired LLM API credentials in the server environment; sandboxed deployments blocking outbound LLM calls; misconfigured agent factory; the underlying agent hitting its own internal error. The poor log line ('Error invoking agent: %s', e) often hides the real cause, forcing developers to debug blind.","solutions":["Check the chained exception (raise ... from e preserves it) — print e.__cause__ or enable traceback logging to see the root cause.","Verify the agent's runtime prerequisites: API keys set, network egress allowed, factory callable returns a healthy agent.","Test the agent directly (await agent.invoke(query, sid)) outside the executor to isolate executor vs agent failure.","Fix the logging bug: use print(f'Error invoking agent: {e}') or logging.exception(...) so the actual error appears in server logs."],"exampleFix":"# before\nexcept Exception as e:\n    print(\"Error invoking agent: %s\", e)  # literal '%s' in output, cause hidden\n    raise ServerError(error=ValueError(f\"Error invoking agent: {e}\")) from e\n# after\nexcept Exception as e:\n    logging.exception(\"Error invoking agent\")  # full traceback including __cause__\n    raise ServerError(error=ValueError(f\"Error invoking agent: {e}\")) from e","handlingStrategy":"try-catch","validationCode":"# verify agent prerequisites before serving requests\nassert os.environ.get('LLM_API_KEY'), 'missing LLM_API_KEY'\nagent = await agent_factory()  # fail fast at startup, not per request","typeGuard":null,"tryCatchPattern":"try:\n    result = await agent.invoke(query, context.context_id)\nexcept ServerError as e:\n    root = e.error.message if e.error else str(e)\n    if root.startswith('Error invoking agent:'):\n        cause = e.__cause__ or e  # original exception is chained\n        log.error('agent failure: %r', cause)\n        # surface cause details, do not retry blindly","preventionTips":["Fail fast: construct the agent via its factory at startup so config/key errors surface before traffic.","Use logging.exception or f-strings so the chained cause is visible (the shipped print uses %s literally).","Keep client and server a2a-sdk versions in sync to avoid serialization-shaped invoke failures."],"tags":["a2a","wrapper-exception","logging","agent-runtime"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}