Skip to content

Conversation

angus-langchain
Copy link
Contributor

@angus-langchain angus-langchain commented Oct 12, 2025

Description

Use RunTree API for openai agents sdk to improve tracing devex by allowing for input/output processing, nested traces with @traceable and wrap_openai.

Test Plan

  • Added unit tests

Resolves #2063

@angus-langchain angus-langchain changed the title openai ai agents interoperability feat(python): OpenAI Agents interoperability Oct 12, 2025
@angus-langchain angus-langchain changed the title feat(python): OpenAI Agents interoperability feat(python): OpenAI Agents Tracing Interoperability Oct 12, 2025
# Avoid calling into importlib on every call to __version__

__version__ = "0.4.34"
__version__ = "0.4.35rc1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert before merging

new_run.post()

ctx = copy_context()
ctx.run(_context._PARENT_RUN_TREE.set, new_run)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is storing context necessary? We're just pulling the parent out of the span maps aren't we?

Copy link
Contributor Author

@angus-langchain angus-langchain Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifying the context is what enables @traceable and wrap_openai to automatically find the agent span as a parent without us having to pass it explicitly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

via setting _PARENT_RUN_TREE

project_name: Optional[str]
name: Optional[str]
run_tree: rt.RunTree
context: contextvars.Context
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below, do we need to store context here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct though, we don't need to actually store it in the RunData map

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

parent_run_id: Optional[str]
project_name: Optional[str]
name: Optional[str]
run_tree: rt.RunTree
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not just store RunTrees directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are, just importing from langsmith import run_trees as rt

@angus-langchain angus-langchain merged commit 14b8e01 into main Oct 14, 2025
17 of 20 checks passed
@angus-langchain angus-langchain deleted the angus/openai-agents-interoperability branch October 14, 2025 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Improved tracing with Open AI Agent SDK

2 participants