Skip to content

Conversation

@Ota1022
Copy link

@Ota1022 Ota1022 commented Feb 2, 2026

Summary

This PR adds a Go example to the "Step 5: Build an Interactive Assistant" section in the getting-started documentation.

Changes

  • Added a complete Go example for the interactive weather assistant alongside the existing Node.js, Python, and .NET examples
  • The example demonstrates:
    • Using copilot.DefineTool to define a weather tool with typed parameters and results
    • Creating a copilot.NewClient and session with streaming enabled
    • Handling assistant.message_delta events for real-time output
    • Handling session.idle events for consistent output formatting
    • Building an interactive console loop using bufio.Scanner

Why

The getting-started guide already has comprehensive examples for Node.js, Python, and .NET for the interactive assistant section, but was missing the Go equivalent. Steps 1–4 all include Go examples, so this addition ensures Go developers have the same level of guidance as other language users in Step 5.

Testing

The code follows the established patterns in the Go SDK and matches the structure of other Go examples in the documentation (Steps 2–4).

Copilot AI review requested due to automatic review settings February 2, 2026 11:18
@Ota1022 Ota1022 requested a review from a team as a code owner February 2, 2026 11:18
Copy link
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

Adds a Go code sample to “Step 5: Build an Interactive Assistant” in the getting-started guide so Go developers have an equivalent interactive weather assistant example alongside Node.js, Python, and .NET.

Changes:

  • Added a Go <details> section with a complete interactive weather assistant example using typed tools.
  • Demonstrates streaming output via assistant.message_delta and an interactive loop using bufio.Scanner.
  • Includes run instructions for the new Go example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


session.On(func(event copilot.SessionEvent) {
if event.Type == "assistant.message_delta" {
fmt.Print(*event.Data.DeltaContent)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

event.Data.DeltaContent is a pointer and may be nil (the Go SDK types mark it as omitempty). Dereferencing it unconditionally can panic at runtime; guard for nil before printing (or handle empty deltas).

Suggested change
fmt.Print(*event.Data.DeltaContent)
if event.Data != nil && event.Data.DeltaContent != nil {
fmt.Print(*event.Data.DeltaContent)
}

Copilot uses AI. Check for mistakes.
Copy link
Author

@Ota1022 Ota1022 Feb 2, 2026

Choose a reason for hiding this comment

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

Fixed, though event.Data is a value type (not a pointer), so only DeltaContent needs a nil check.
fix: simplify condition in session event handling for Go example

Comment on lines 870 to 872
if err != nil {
log.Fatal(err)
}
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

Using log.Fatal here will call os.Exit(1) and skip deferred cleanup (e.g., defer client.Stop() above). Prefer returning from main after logging, or explicitly stop/close resources before exiting so the example doesn't leak the underlying process/session on errors.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed. Same issue exists in Steps 3–4 as well — can address separately.

Comment on lines +860 to +862
if !scanner.Scan() {
break
}
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The loop exits when scanner.Scan() returns false, but the example never checks scanner.Err(). Add an error check after the loop so input/read errors don't get silently swallowed (and so users can distinguish EOF from an actual failure).

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

@Ota1022
Copy link
Author

Ota1022 commented Feb 2, 2026

Resolved all Copilot review comments. Verified the example compiles and runs correctly!

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.

1 participant