-
Notifications
You must be signed in to change notification settings - Fork 10
feat(openai): support handoffs #82
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
+65
−19
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from dataclasses import dataclass | ||
| from typing import Any | ||
|
|
||
| from agents import Handoff | ||
| from agents.run_context import RunContextWrapper | ||
|
|
||
|
|
||
| @dataclass | ||
| class CadenceHandoff: | ||
| """Serializable representation of a Handoff for crossing the Cadence activity boundary. | ||
| Only the fields needed by the model (tool schema) are kept; callable/runtime | ||
| fields are reconstructed with no-op stubs on the activity side.""" | ||
|
|
||
| tool_name: str | ||
| tool_description: str | ||
| input_json_schema: dict[str, Any] | ||
| agent_name: str | ||
| strict_json_schema: bool = True | ||
|
|
||
|
|
||
| def to_cadence_handoff(handoff: Handoff[Any, Any]) -> CadenceHandoff: | ||
| return CadenceHandoff( | ||
| tool_name=handoff.tool_name, | ||
| tool_description=handoff.tool_description, | ||
| input_json_schema=handoff.input_json_schema, | ||
| agent_name=handoff.agent_name, | ||
| strict_json_schema=handoff.strict_json_schema, | ||
| ) | ||
|
|
||
|
|
||
| def from_cadence_handoff(ch: CadenceHandoff) -> Handoff[Any, Any]: | ||
| async def noop_invoke(_ctx: RunContextWrapper[Any], _json: str): | ||
| raise RuntimeError("Handoff invocation is handled by the runner, not the model") | ||
|
|
||
| return Handoff( | ||
| tool_name=ch.tool_name, | ||
| tool_description=ch.tool_description, | ||
| input_json_schema=ch.input_json_schema, | ||
| on_invoke_handoff=noop_invoke, | ||
| agent_name=ch.agent_name, | ||
| strict_json_schema=ch.strict_json_schema, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import cadence | ||
| from cadence.contrib.openai import OpenAIActivities | ||
|
|
||
|
|
||
| cadence_registry = cadence.Registry() | ||
| cadence_registry.register_activities(OpenAIActivities()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Quality: Module-level side effect in cadence_registry.py
cadence_registry.py instantiates
OpenAIActivities()and registers it at import time. This means merely importing the module triggers side effects (object creation, registration). Consider using a factory function or lazy initialization pattern so consumers have explicit control over when registration happens.Was this helpful? React with 👍 / 👎 | Reply
gitar fixto apply this suggestionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected