Skip to content

nexus_operation_as_tool #949

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 2 commits into from
Jul 10, 2025
Merged

nexus_operation_as_tool #949

merged 2 commits into from
Jul 10, 2025

Conversation

dandavison
Copy link
Contributor

Add a Nexus operation version of activity_as_tool.

@dandavison dandavison requested a review from a team as a code owner July 8, 2025 21:03
@dandavison dandavison force-pushed the nexus-operation-as-tool-rebase branch 2 times, most recently from 4ddba85 to 9cde5d0 Compare July 8, 2025 21:49
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM as is. Admittedly I have never reviewed the activity as tool code in depth either. Would like @tconley1428 to approve.

}
operation_callable.__name__ = operation.name

schema = function_schema(operation_callable)
Copy link
Member

Choose a reason for hiding this comment

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

We support activities having access to an agent context as the first param but I am concerned Nexus operation limitations of single param forbid having context as the first param and input as the second. Suggestions? I think we may just have to document for now that tools backed by Nexus operations can't have access to context at this time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that is ok since we provide nexus_operation_as_tool as a convenience method. You should still be able to define a regular function tool, grab what you need from the context, and invoke the Nexus operation from there.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed behavior is ok, it's just the optics are confusing/inconsistent. "So, in-workflow tools can have mutable context, activity tools can have immutable context, and nexus tools can have no context?" We need to document this at least I think.

Copy link
Contributor

@tconley1428 tconley1428 left a comment

Choose a reason for hiding this comment

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

I would like to see the tests left intact, but otherwise looks good.

"""Error that occurs when a tool output could not be serialized."""


def activity_as_tool(
Copy link
Contributor

Choose a reason for hiding this comment

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

This file got removed, now located in temporal_openai_agents.workflow

@@ -287,8 +306,11 @@ async def run(self, question: str) -> str:
openai_agents.workflow.activity_as_tool(
get_weather_object, start_to_close_timeout=timedelta(seconds=10)
),
openai_agents.workflow.activity_as_tool(
get_weather_country, start_to_close_timeout=timedelta(seconds=10)
nexus_operation_as_tool(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add the tool and extend the test to call it rather than replacing one.

@dandavison
Copy link
Contributor Author

We should add the tool and extend the test to call it rather than replacing one.

Good call @tconley1428, done that.

@dandavison dandavison force-pushed the nexus-operation-as-tool-rebase branch from f329f07 to 4db4051 Compare July 10, 2025 20:15
@dandavison dandavison force-pushed the nexus-operation-as-tool-rebase branch from 4db4051 to f501b66 Compare July 10, 2025 21:02
@dandavison dandavison force-pushed the nexus-operation-as-tool-rebase branch from 451d5c6 to beb684a Compare July 10, 2025 22:07
@dandavison dandavison merged commit e73d6b5 into main Jul 10, 2025
37 of 40 checks passed
@dandavison dandavison deleted the nexus-operation-as-tool-rebase branch July 10, 2025 23:18
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.

4 participants