Skip to content

feat(agents): run local tools during session creation - #1141

Merged
apcha-oai merged 7 commits into
mainfrom
apcha/agents-creation-tools
Oct 5, 2026
Merged

apcha-oai merged 7 commits into
mainfrom
apcha/agents-creation-tools

Conversation

@apcha-oai

@apcha-oai apcha-oai commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Run local function tools while streaming a session's initial prompt, including sessions with environment: none. Previously, local handlers required creating an idle session and then submitting a separate follow-up prompt.

Before:

var followUp = AgentSessionStreamParams.builder()
    .sessionId(existingIdleSessionId)
    .input("Look up item A123")
    .toolHandler(lookup.name(), lookup.handler())
    .build();
var stream = client.beta().agents().sessions().stream(followUp);

After:

var creation = SessionCreateParams.builder()
    .agent(agent) // Includes lookup.definition().
    .environmentNone()
    .input("Look up item A123")
    .build();
var handlers = AgentToolHandlers.builder()
    .toolHandler(lookup.name(), lookup.handler())
    .build();

try (var stream = client.beta().agents().sessions().createStreaming(creation, handlers)) {
    System.out.println(AgentTurnResults.getFinalResult(stream).outputText());
}

The async service accepts the same overload and completion-stage handlers. Callbacks remain local; both creation and follow-up streams reuse the existing dispatcher, retry behavior, and opt-in result collection.

@apcha-oai
apcha-oai requested a review from a team as a code owner October 5, 2026 14:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T16:30:41.210939Z 41a3ef1 Manual request
🔒 Security Review ✅ Completed 2026-10-05T16:30:48.553006Z 41a3ef1 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@apcha-oai

Copy link
Copy Markdown
Contributor Author

@codex review pls

@openai-sdks

openai-sdks Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

OkTest Summary

✅ 236/236 SDK tests passed in 16.916s for Java SDK PR #1141.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 662ms
tests/chat-completions-create.test.ts ✅ Passed 415ms
tests/chat-completions-stream.test.ts ✅ Passed 636ms
tests/files-content-binary.test.ts ✅ Passed 259ms
tests/files-create-multipart.test.ts ✅ Passed 327ms
tests/files-list-pagination.test.ts ✅ Passed 356ms
tests/initialize-config.test.ts ✅ Passed 206ms
tests/instance-isolation.test.ts ✅ Passed 178ms
tests/models-list.test.ts ✅ Passed 343ms
tests/responses-background-lifecycle.test.ts ✅ Passed 228ms
tests/responses-body-method-errors.test.ts ✅ Passed 483ms
tests/responses-cancel-timeout.test.ts ✅ Passed 217ms
tests/responses-cancel.test.ts ✅ Passed 222ms
tests/responses-compact-retries.test.ts ✅ Passed 361ms
tests/responses-compact.test.ts ✅ Passed 311ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 282ms
tests/responses-create-advanced.test.ts ✅ Passed 1.546s
tests/responses-create-disconnect.test.ts ✅ Passed 1.006s
tests/responses-create-errors.test.ts ✅ Passed 317ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 229ms
tests/responses-create-retries.test.ts ✅ Passed 235ms
tests/responses-create-stream-failures.test.ts ✅ Passed 1.407s
tests/responses-create-stream-timeout.test.ts ✅ Passed 267ms
tests/responses-create-stream-wire.test.ts ✅ Passed 6.607s
tests/responses-create-stream.test.ts ✅ Passed 276ms
tests/responses-create-terminal-states.test.ts ✅ Passed 476ms
tests/responses-create-timeout.test.ts ✅ Passed 200ms
tests/responses-create.test.ts ✅ Passed 278ms
tests/responses-delete.test.ts ✅ Passed 267ms
tests/responses-input-items-errors.test.ts ✅ Passed 267ms
tests/responses-input-items-list.test.ts ✅ Passed 289ms
tests/responses-input-items-options.test.ts ✅ Passed 328ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 227ms
tests/responses-input-tokens-count.test.ts ✅ Passed 248ms
tests/responses-malformed-inputs.test.ts ✅ Passed 5.024s
tests/responses-not-found-errors.test.ts ✅ Passed 444ms
tests/responses-parse.test.ts ✅ Passed 640ms
tests/responses-retrieve-retries.test.ts ✅ Passed 325ms
tests/responses-retrieve.test.ts ✅ Passed 278ms
tests/responses-stored-method-errors.test.ts ✅ Passed 1.036s
tests/retry-behavior.test.ts ✅ Passed 3.466s
tests/sdk-error-shape.test.ts ✅ Passed 527ms

View OkTest run #37341090302

SDK merge (6b06f272631c) · head (41a3ef1c74f4) · base (c50d94b56e76) · OkTest (505ac0e34283)

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Castiron custom code

Evaluated main: c50d94b56e76317888b7018fd51c6704c89865b5.

✅ No new custom-code files detected.

91 mixed files remain; 4 existing customizations changed.

Compared c50d94b56e76 → 41a3ef1c74f4. Generated baselines verified.

File Result Current custom patch
openai-java-core/src/main/kotlin/com/openai/services/async/beta/agents/SessionServiceAsync.kt Existing customization changed +32 / −0
openai-java-core/src/main/kotlin/com/openai/services/async/beta/agents/SessionServiceAsyncImpl.kt Existing customization changed +41 / −1
openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/agents/SessionService.kt Existing customization changed +35 / −0
openai-java-core/src/main/kotlin/com/openai/services/blocking/beta/agents/SessionServiceImpl.kt Existing customization changed +25 / −0
87 existing customizations unchanged
  • openai-java-core/src/main/kotlin/com/openai/models/audio/AudioResponseFormat.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/vaults/credentials/CredentialAuth.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/vaults/credentials/CredentialAuthCreateParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/agents/vaults/credentials/CredentialAuthRotateParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponse.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponseStreamEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/beta/responses/BetaResponsesServerEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionMessageFunctionToolCall.kt
  • openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionToolMessageParam.kt
  • openai-java-core/src/main/kotlin/com/openai/models/embeddings/Embedding.kt
  • openai-java-core/src/main/kotlin/com/openai/models/embeddings/EmbeddingCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/Response.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseCreateParams.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionToolCall.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseFunctionWebSearch.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseInputItem.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseStreamEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponseTextConfig.kt
  • openai-java-core/src/main/kotlin/com/openai/models/responses/ResponsesServerEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/videos/Video.kt
  • openai-java-core/src/main/kotlin/com/openai/models/webhooks/UnwrapWebhookEvent.kt
  • openai-java-core/src/main/kotlin/com/openai/models/webhooks/WebhookEndpointWithSecret.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/BetaServiceAsync.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/BetaServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/ImageServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/ResponseServiceAsync.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/ResponseServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/SkillServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/VideoServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/WebhookServiceAsync.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/WebhookServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/audio/TranscriptionServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/audio/TranslationServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/audio/VoiceServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/chat/ChatCompletionServiceAsync.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/finetuning/checkpoints/PermissionServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/async/skills/VersionServiceAsyncImpl.kt
  • openai-java-core/src/main/kotlin/com/openai/services/blocking/BetaService.kt
  • openai-java-core/src/main/kotlin/com/openai/services/blocking/BetaServiceImpl.kt

47 more in the full report.

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 37341145298 --repo openai/openai-java \
  --name castiron-custom-code-37341145298-1 --dir /tmp/castiron-custom-code-37341145298-1
git apply --stat /tmp/castiron-custom-code-37341145298-1/custom-code.patch
cat /tmp/castiron-custom-code-37341145298-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin c50d94b56e76317888b7018fd51c6704c89865b5 41a3ef1c74f409da74a33e362d30ecf9e3c357dc
python3 scripts/castiron/custom_code_report.py report \
  --base c50d94b56e76317888b7018fd51c6704c89865b5 \
  --head 41a3ef1c74f409da74a33e362d30ecf9e3c357dc --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-41a3ef1c74f4
cat /tmp/castiron-custom-code-41a3ef1c74f4/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 3f586ba2a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 3f586ba2a3

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b1a4492569

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@markstuart-oai markstuart-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed b1a4492. The existing finding about creation without input remains valid. A self-hosted session can send created/idle events without starting a turn. The new overload then throws at EOF in both blocking and async consumption, even when the caller requests raw events only. Preserve whether creation has input and allow idle to finish that raw stream, while retaining the follow-up stream's turn check.

The shared dispatcher, result collection, retry keys, and response cleanup otherwise look consistent. I found no additional distinct issue. Hosted tests, lint, build, API/Jackson compatibility, Java 8/25 runtime checks, and required CI passed for this head. Source review only; I did not run local tests or live smoke tests.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed b1a4492. The existing P2 no-input creation finding remains valid: self-hosted creation may omit input, but the new handler overload loses that distinction and only treats idle as terminal after a turn has ended. Both blocking raw iteration and async subscription then report unexpected EOF for a valid created/idle stream—even with an empty handler registry. Preserve input-less creation completion separately from the follow-up helper's completed-turn requirement. The final-result helper's initial-input requirement should not make raw event consumption fail.

Reviewed all ten changed files and supporting stream/result collection, request-option, retry and response-cleanup paths. No additional distinct finding. Exact-head hosted tests, lint, build, API/Jackson compatibility, Java 8/25 runtime, version matrix, Castiron and required CI passed; git diff --check passed. No local SDK tests or live API calls. Referencing the existing inline thread rather than duplicating it.

@apcha-oai

Copy link
Copy Markdown
Contributor Author

@codex review pls

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 94cfa2268a

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94cfa2268a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@apcha-oai

Copy link
Copy Markdown
Contributor Author

@codex review pls

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: f910f8e749

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: f910f8e749

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/** 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<*>>>

Copy link
Copy Markdown
Contributor

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:10

Creation builds AgentSessionStreamSupport with params == null, so its onToolError is 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 sanitized Tool handler failed. result but the application cannot log or monitor the real cause.

Suggested fix: carry an optional Consumer<AgentToolError> in AgentToolHandlers, pass it into creation stream support, and cover argument, execution, and output failures (including observer exceptions) in the blocking and async creation tests.

@apcha-oai

Copy link
Copy Markdown
Contributor Author

@codex review pls

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 41a3ef1c74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 41a3ef1c74

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@markstuart-oai markstuart-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed 41a3ef1. The prior input-free creation finding is fixed. Raw blocking and async streams can end at idle without a turn, while finalResult still rejects an incomplete turn. Shared dispatch preserves callback cleanup, tool-result idempotency, and the existing follow-up stream behavior.

The open suggestion to expose a creation tool-error observer remains an API follow-up. Source review only. Hosted build, lint, tests, API compatibility, Jackson, Java 8/25, required checks, and Castiron passed. Live smoke tests are author-reported; Java OkTest was still running in the request. No local workloads were run.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the full updated diff at 41a3ef1. The prior no-input creation-stream blocker is fixed for both blocking and async streams: raw created/idle iteration can complete without a turn, while final-result collection still reports an incomplete stream. Deriving input presence from raw JSON also preserves future input shapes. The parameterized regressions cover both stream styles and collection semantics. No additional actionable findings. Exact-head hosted checks passed (optional jobs skipped); source/hosted-CI review only, no local tests or live API calls.

@apcha-oai
apcha-oai added this pull request to the merge queue Oct 5, 2026
Merged via the queue into main with commit bffddc4 Oct 5, 2026
14 checks passed
@openai-sdks openai-sdks Bot mentioned this pull request Oct 5, 2026
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