Skip to content

examples: use tool call arguments in the realtime sample#1126

Closed
Rohan5commit wants to merge 1 commit into
openai:mainfrom
Rohan5commit:examples/realtime-tool-arguments-20260427
Closed

examples: use tool call arguments in the realtime sample#1126
Rohan5commit wants to merge 1 commit into
openai:mainfrom
Rohan5commit:examples/realtime-tool-arguments-20260427

Conversation

@Rohan5commit
Copy link
Copy Markdown
Contributor

Summary

  • parse the model-provided function arguments in the realtime tools example before constructing the tool output item
  • use the requested location and unit values instead of always sending a hard-coded weather lookup

Related issue

Guideline alignment

  • keeps the change to a single manually maintained example file with no generated code changes
  • makes the sample closer to a real tool-calling flow without changing library behavior

Validation

  • ran git diff --check
  • did not run a local dotnet build because the dotnet CLI is unavailable in this environment

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Realtime tools example to use the model-provided tool call arguments (location/unit) when producing the tool output item, making the sample reflect a more realistic tool-calling flow.

Changes:

  • Parse RealtimeFunctionCallItem.FunctionArguments as JSON and extract location/unit.
  • Pass extracted location/unit into GetCurrentWeather instead of using hard-coded values.
  • Update the console output to include the requested location.

Comment on lines +213 to +219
using JsonDocument argumentsJson = JsonDocument.Parse(functionCallItem.FunctionArguments.ToString());
string location = argumentsJson.RootElement.TryGetProperty("location", out JsonElement locationElement)
? locationElement.GetString() ?? "San Francisco, CA"
: "San Francisco, CA";
string unit = argumentsJson.RootElement.TryGetProperty("unit", out JsonElement unitElement)
? unitElement.GetString() ?? "celsius"
: "celsius";
Copy link
Copy Markdown

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

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: 95ca213328

ℹ️ 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".

hasToolCalls = true;

Console.WriteLine($">> Calling {functionCallItem.FunctionName} function...");
using JsonDocument argumentsJson = JsonDocument.Parse(functionCallItem.FunctionArguments.ToString());
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle empty arguments before JSON parsing

functionCallItem.FunctionArguments is a string payload and can be empty in realtime function-call events; parsing it unconditionally with JsonDocument.Parse(...) will throw JsonException and stop the sample before it can submit tool output. This is a regression from the previous behavior (which continued with defaults) and can surface whenever the model returns an empty/malformed arguments string, so the example should defensively fall back (for example, treat empty input as {}) before parsing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

@jsquire jsquire left a comment

Choose a reason for hiding this comment

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

This is a duplicate of #1124. Closing this one out; please focus efforts there.

@jsquire jsquire closed this Apr 27, 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.

[FEATURE REQ] Please improve the Realtime sample

3 participants