Skip to content

Adding an end to end test which uses an openai service account #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
- if: ${{ !endsWith(matrix.os, '-arm') }}
run: poe test ${{matrix.pytestExtraArgs}} -s --workflow-environment time-skipping --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}--time-skipping.xml
timeout-minutes: 10
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# Check cloud if proper target and not on fork
- if: ${{ matrix.cloudTestTarget && (github.event.pull_request.head.repo.full_name == '' || github.event.pull_request.head.repo.full_name == 'temporalio/sdk-python') }}
run: poe test ${{matrix.pytestExtraArgs}} -s -k test_cloud_client --junit-xml=junit-xml/${{ matrix.python }}--${{ matrix.os }}--cloud.xml
Expand Down
36 changes: 35 additions & 1 deletion tests/contrib/test_openai.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import uuid
from dataclasses import dataclass
Expand All @@ -19,6 +20,9 @@
set_open_ai_agent_temporal_overrides,
)
from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool
from temporalio.contrib.openai_agents.trace_interceptor import (
OpenAIAgentsTracingInterceptor,
)
from tests.helpers import new_worker

with workflow.unsafe.imports_passed_through():
Expand Down Expand Up @@ -167,6 +171,32 @@ async def test_hello_world_agent(client: Client):
assert result == "test"


async def test_end_to_end(client: Client):
if "OPENAI_API_KEY" not in os.environ:
pytest.skip("No openai API key")

new_config = client.config()
new_config["data_converter"] = open_ai_data_converter
client = Client(**new_config)

model_params = ModelActivityParameters(start_to_close_timeout=timedelta(seconds=10))
with set_open_ai_agent_temporal_overrides(model_params):
async with new_worker(
client,
HelloWorldAgent,
activities=[ModelActivity().invoke_model_activity],
interceptors=[OpenAIAgentsTracingInterceptor()],
) as worker:
result = await client.execute_workflow(
HelloWorldAgent.run,
"Tell me about recursion in programming. Include the word 'function'",
id=f"hello-workflow-{uuid.uuid4()}",
task_queue=worker.task_queue,
execution_timeout=timedelta(seconds=30),
)
assert "function" in result.lower()


@dataclass
class Weather:
city: str
Expand Down Expand Up @@ -225,7 +255,7 @@ class ToolsWorkflow:
@workflow.run
async def run(self, question: str) -> str:
agent = Agent(
name="Hello world",
name="Tools Workflow",
instructions="You are a helpful agent.",
tools=[
activity_as_tool(
Expand Down Expand Up @@ -255,6 +285,7 @@ async def test_tool_workflow(client: Client):
client,
ToolsWorkflow,
activities=[model_activity.invoke_model_activity, get_weather],
interceptors=[OpenAIAgentsTracingInterceptor()],
) as worker:
workflow_handle = await client.start_workflow(
ToolsWorkflow.run,
Expand Down Expand Up @@ -476,6 +507,7 @@ async def test_research_workflow(client: Client):
client,
ResearchWorkflow,
activities=[model_activity.invoke_model_activity, get_weather],
interceptors=[OpenAIAgentsTracingInterceptor()],
) as worker:
workflow_handle = await client.start_workflow(
ResearchWorkflow.run,
Expand Down Expand Up @@ -686,6 +718,7 @@ async def test_agents_as_tools_workflow(client: Client):
client,
AgentsAsToolsWorkflow,
activities=[model_activity.invoke_model_activity],
interceptors=[OpenAIAgentsTracingInterceptor()],
) as worker:
workflow_handle = await client.start_workflow(
AgentsAsToolsWorkflow.run,
Expand Down Expand Up @@ -1043,6 +1076,7 @@ async def test_customer_service_workflow(client: Client):
client,
CustomerServiceWorkflow,
activities=[model_activity.invoke_model_activity],
interceptors=[OpenAIAgentsTracingInterceptor()],
) as worker:
workflow_handle = await client.start_workflow(
CustomerServiceWorkflow.run,
Expand Down
Loading