Skip to content

[Bug] openai_agents: activity_as_tool / nexus_operation_as_tool fail or wedge the workflow when the model sends invalid tool arguments #91

Closed

Description

@avanish-garg

What are you really trying to do?

Expose a Temporal activity to an OpenAI agent with activity_as_tool and let the agent recover when the
model calls it with bad arguments, the way it does for a normal @function_tool.

Describe the bug

run_activity in python/openai_agents/src/temporalio/openai_agents/workflow.py parses the model's
arguments inside the workflow with no error handling: json.loads(input) and
schema.params_pydantic_model(**json_data). nexus_operation_as_tool has the same pattern.

  • Missing argument, wrong type, or a JSON list/null: pydantic raises ValidationError, which the Agents SDK
    wraps in UserError. UserError is not a Temporal failure type, so the workflow task fails and is retried
    forever. The workflow stays RUNNING and nothing is shown to the user until the execution timeout.
  • Non-JSON arguments: ApplicationError is raised and the whole workflow fails with AgentsWorkflowError.

A stock @function_tool with the same four inputs recovers: the SDK returns the error text to the model
(failure_error_function), the model retries, and the run completes. LLMs routinely hallucinate or omit
arguments (especially with strict_json_schema=False), so one bad call takes down a durable agent. The README
already treats failure_error_function as a first-class option for MCP tools.

Minimal Reproduction

(runs against the released packages; swap the arguments for '{"city": "Paris"' to see the non-JSON variant)

import asyncio, uuid
from datetime import timedelta
from agents import Agent, Runner
from temporalio import activity, workflow
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker
from temporalio.openai_agents import workflow as oaw
from temporalio.openai_agents.testing import AgentEnvironment, TestModel, ResponseBuilders

@activity.defn
async def get_weather(city: str, units: int) -> str:
    return f"sunny in {city}"

@workflow.defn
class W:
    @workflow.run
    async def run(self, q: str) -> str:
        agent = Agent(name="a", instructions="x", tools=[
            oaw.activity_as_tool(get_weather, start_to_close_timeout=timedelta(seconds=10))])
        return (await Runner.run(agent, q)).final_output

async def main():
    model = TestModel.returning_responses([
        ResponseBuilders.tool_call('{"city": "Paris"}', "get_weather"),  # "units" is missing
        ResponseBuilders.output_message("recovered")])
    async with AgentEnvironment(model=model) as env:
        async with await WorkflowEnvironment.start_local() as wenv:
            client = env.applied_on_client(wenv.client)
            async with Worker(client, task_queue="q", workflows=[W], activities=[get_weather]):
                h = await client.start_workflow(W.run, "hi", id=str(uuid.uuid4()),
                    task_queue="q", execution_timeout=timedelta(seconds=15))
                try:
                    print("RESULT:", await h.result())
                except Exception as e:
                    print("EXC:", type(e).__name__, repr(e.__cause__))
                print("status:", (await h.describe()).status)

asyncio.run(main())

Result: a timeout, with the workflow task failing repeatedly
(Error running tool get_weather: 1 validation error ... units Field required). Expected: RESULT: recovered.
The same happens for a wrong-typed argument, a JSON list and JSON null.

Environment/Versions

  • OS and processor: macOS, arm64
  • Temporal Version: temporalio 1.34.0, temporalio-openai-agents from main @ 3582afe, openai-agents 0.22.0, Python 3.11
  • Are you using Docker or Kubernetes or building Temporal from source? No, local dev server via WorkflowEnvironment.start_local()

Activity

  1. added
    bug
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions