OpenAI Agents SDK + Temporal

Getting this error when configuring OpenAI SDK w/ Temporal.

ValueError: Temporal workflows require a model name to be a string in the run config and/or agent.

        agent = Agent(
            name="Assistant",
            instructions="You only respond in haikus.",
            model=LitellmModel(
                model="openai/gpt-4o-(US)",
                base_url="https://llmproxy.myapp.in/v1",
                api_key="sk-XXXXXXXXXXXXXX",
            )
        )

Worker

async def worker_main():
    # Use the plugin to configure Temporal for use with OpenAI Agents SDK
    client = await Client.connect(
        "localhost:7233",
        plugins=[
            OpenAIAgentsPlugin(
                model_params=ModelActivityParameters(
                    start_to_close_timeout=timedelta(seconds=30)
                ),
                model_provider=LitellmProvider()
            ),
        ],
    )

    worker = Worker(
        client,
        task_queue="my-task-queue",
        workflows=[HelloWorldAgent],
    )
    await worker.run()

Any guidance is appreciated.

Try:

agent = Agent(
            name="Assistant",
            instructions="You only respond in haikus.",
            model="openai/gpt-4o-(US)"
        )
class LitellmProviderWithOptions(LitellmProvider):
    def __init__(self, base_url: str = None, api_key: str = None):
        self._base_url = base_url
        self._api_key = api_key

    def get_model(self, model_name: str | None) -> Model:
        return LitellmModel(model_name or DEFAULT_MODEL,
                            base_url=self._base_url,
                            api_key=self._api_key)

async def worker_main():
    # Use the plugin to configure Temporal for use with OpenAI Agents SDK
    client = await Client.connect(
        "localhost:7233",
        plugins=[
            OpenAIAgentsPlugin(
                model_params=ModelActivityParameters(
                    start_to_close_timeout=timedelta(seconds=30)
                ),
                model_provider=LitellmProviderWithOptions(
                    base_url="https://llmproxy.myapp.in/v1",
                    api_key="sk-XXXXXXXXXXXXXX",
                )
            ),
        ],
    )

Thanks @maxim. Got it working.

1 Like