RunStream starts the agent's interaction loop and returns a channel of events. The returned channel is closed when the loop terminates (success, error, or context cancellation). Each iteration: sends messages to the model, streams the response, executes any tool calls, and loops until the model sign
(ctx context.Context, sess *session.Session)
| 223 | // the response, executes any tool calls, and loops until the model signals stop |
| 224 | // or the iteration limit is reached. |
| 225 | func (r *LocalRuntime) RunStream(ctx context.Context, sess *session.Session) <-chan Event { |
| 226 | slog.DebugContext(ctx, "Starting runtime stream", "agent", r.currentAgentName(), "session_id", sess.ID) |
| 227 | events := make(chan Event, defaultEventChannelCapacity) |
| 228 | |
| 229 | go r.runStreamLoop(ctx, sess, events) |
| 230 | return r.observe(ctx, sess, events) |
| 231 | } |
| 232 | |
| 233 | // runStreamLoop is the body of RunStream. Pulled out of the anonymous |
| 234 | // goroutine so it has a real name in stack traces and is easier to navigate |