You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Why iterators work for multi-turn:** Each call to `Stream()` returns an iterator over a **new channel** created for that turn. When the agent finishes responding (loops back to read the next input), it closes that turn's stream channel, causing the user's `for range` loop to exit naturally. The user then calls `Send()` with the next input and `Stream()` again to get a new iterator for the next turn's responses.
93
-
94
92
### 1.3 BidiFlow
95
93
96
94
```go
@@ -99,9 +97,27 @@ type BidiFlow[Init, In, Out, Stream any] struct {
99
97
}
100
98
```
101
99
102
-
### 1.4 Agent
100
+
### 1.4 Responder
101
+
102
+
`Responder` wraps the output channel for agents, providing methods to send data and signal turn boundaries.
103
+
104
+
```go
105
+
// Responder wraps the output channel with turn signaling for multi-turn agents.
106
+
typeResponder[T any] struct {
107
+
ch chan<- streamChunk[T] // internal, unexported
108
+
}
109
+
110
+
// Send sends a streamed chunk to the consumer.
111
+
func(r *Responder[T]) Send(dataT)
112
+
113
+
// EndTurn signals that the agent has finished responding to the current input.
114
+
// The consumer's Stream() iterator will exit, allowing them to send the next input.
115
+
func (r *Responder[T]) EndTurn()
116
+
```
117
+
118
+
### 1.5 Agent
103
119
104
-
Agent adds session state management on top of BidiFlow.
120
+
Agent adds session state management on top of BidiFlow with turn semantics.
105
121
106
122
```go
107
123
// Artifact represents a named collection of parts produced during a session.
@@ -135,9 +151,9 @@ type AgentResult[Out any] struct {
135
151
// AgentFunc is the function signature for agents.
136
152
typeAgentFunc[State, In, Out, Stream any] func(
137
153
ctx context.Context,
138
-
inputStream <-chanIn,
139
154
sess *session.Session[State],
140
-
sendChunk core.StreamCallback[Stream],
155
+
inCh <-chanIn,
156
+
resp *Responder[Stream],
141
157
) (AgentResult[Out], error)
142
158
```
143
159
@@ -366,7 +382,6 @@ import (
366
382
"context"
367
383
"fmt"
368
384
369
-
"github.com/firebase/genkit/go/core"
370
385
"github.com/firebase/genkit/go/genkit"
371
386
)
372
387
@@ -376,13 +391,11 @@ func main() {
376
391
377
392
// Define echo bidi flow (low-level, no turn semantics)
0 commit comments