Repository navigation
feat(agents): run local tools during session creation #1141
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a6b0f79
feat(agents): run local tools during session creation
apcha-oai 3f586ba
style(agents): format shared dispatcher types
apcha-oai b1a4492
Merge branch 'main' into apcha/agents-creation-tools
apcha-oai 94cfa22
fix(agents): finish inputless creation streams at idle
apcha-oai a488fb5
Merge commit 'c50d94b56e76317888b7018fd51c6704c89865b5' into apcha/ag…
apcha-oai f910f8e
fix(agents): preserve raw inputs and follow-up diagnostics
apcha-oai 41a3ef1
test(agents): keep stream regression tests consumer-compatible
apcha-oai 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
32 changes: 32 additions & 0 deletions
32
openai-java-core/src/main/kotlin/com/openai/models/beta/agents/AgentToolHandlers.kt
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,32 @@ | ||
| package com.openai.models.beta.agents | ||
|
|
||
| import java.util.concurrent.CompletableFuture | ||
| import java.util.concurrent.CompletionStage | ||
| import java.util.function.Function | ||
|
|
||
| /** Local function handlers for a beta Agents creation stream. Never sent to the API. */ | ||
| class AgentToolHandlers | ||
| private constructor( | ||
| internal val handlers: Map<String, Function<Map<String, Any?>, CompletionStage<*>>> | ||
| ) { | ||
| companion object { | ||
| @JvmStatic fun builder() = Builder() | ||
| } | ||
|
|
||
| class Builder { | ||
| private val handlers = | ||
| linkedMapOf<String, Function<Map<String, Any?>, CompletionStage<*>>>() | ||
|
|
||
| /** Uses the same return values and sanitized errors as session stream tool handlers. */ | ||
| fun toolHandler(name: String, handler: Function<Map<String, Any?>, Any?>) = apply { | ||
| handlers[name] = Function { CompletableFuture.completedFuture(handler.apply(it)) } | ||
| } | ||
|
|
||
| fun asyncToolHandler( | ||
| name: String, | ||
| handler: Function<Map<String, Any?>, CompletionStage<*>>, | ||
| ) = apply { handlers[name] = handler } | ||
|
|
||
| fun build() = AgentToolHandlers(handlers.toMap()) | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
[Medium] Preserve tool-error observation for creation handlers
openai-java-core/src/main/kotlin/com/openai/models/beta/agents/AgentToolHandlers.kt:10Creation builds
AgentSessionStreamSupportwithparams == null, so itsonToolErroris always null, and this handler container provides no way to supply the observer supported by follow-up streams. If initial-turn arguments are malformed, a handler fails, or its output cannot be serialized, the model gets the sanitizedTool handler failed.result but the application cannot log or monitor the real cause.Suggested fix: carry an optional
Consumer<AgentToolError>inAgentToolHandlers, pass it into creation stream support, and cover argument, execution, and output failures (including observer exceptions) in the blocking and async creation tests.