-
Notifications
You must be signed in to change notification settings - Fork 749
docs: add Go example for interactive weather assistant in Step 5 #318
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
base: main
Are you sure you want to change the base?
docs: add Go example for interactive weather assistant in Step 5 #318
Conversation
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.
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_deltaand an interactive loop usingbufio.Scanner. - Includes run instructions for the new Go example.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/getting-started.md
Outdated
|
|
||
| session.On(func(event copilot.SessionEvent) { | ||
| if event.Type == "assistant.message_delta" { | ||
| fmt.Print(*event.Data.DeltaContent) |
Copilot
AI
Feb 2, 2026
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.
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).
| fmt.Print(*event.Data.DeltaContent) | |
| if event.Data != nil && event.Data.DeltaContent != nil { | |
| fmt.Print(*event.Data.DeltaContent) | |
| } |
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.
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
| if err != nil { | ||
| log.Fatal(err) | ||
| } |
Copilot
AI
Feb 2, 2026
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.
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.
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.
Fixed. Same issue exists in Steps 3–4 as well — can address separately.
| if !scanner.Scan() { | ||
| break | ||
| } |
Copilot
AI
Feb 2, 2026
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.
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).
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.
Fixed.
|
Resolved all Copilot review comments. Verified the example compiles and runs correctly! |
Summary
This PR adds a Go example to the "Step 5: Build an Interactive Assistant" section in the getting-started documentation.
Changes
copilot.DefineToolto define a weather tool with typed parameters and resultscopilot.NewClientand session with streaming enabledassistant.message_deltaevents for real-time outputsession.idleevents for consistent output formattingbufio.ScannerWhy
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).