@@ -22,7 +22,6 @@ import (
2222 "github.com/cloudwego/eino/callbacks"
2323 "github.com/cloudwego/eino/components"
2424 icb "github.com/cloudwego/eino/internal/callbacks"
25- "github.com/cloudwego/eino/schema"
2625)
2726
2827// AgentCallbackInput represents the input passed to agent callbacks during OnStart.
@@ -44,18 +43,18 @@ type AgentCallbackOutput struct {
4443 Events * AsyncIterator [* AgentEvent ]
4544}
4645
47- func copyEventIterator (iter * AsyncIterator [* AgentEvent ] , n int ) []* AsyncIterator [* AgentEvent ] {
46+ func copyTypedEventIterator [ M messageType ] (iter * AsyncIterator [* TypedAgentEvent [ M ]] , n int ) []* AsyncIterator [* TypedAgentEvent [ M ] ] {
4847 if n <= 0 {
4948 return nil
5049 }
5150 if n == 1 {
52- return []* AsyncIterator [* AgentEvent ]{iter }
51+ return []* AsyncIterator [* TypedAgentEvent [ M ] ]{iter }
5352 }
5453
55- iterators := make ([]* AsyncIterator [* AgentEvent ], n )
56- generators := make ([]* AsyncGenerator [* AgentEvent ], n )
54+ iterators := make ([]* AsyncIterator [* TypedAgentEvent [ M ] ], n )
55+ generators := make ([]* AsyncGenerator [* TypedAgentEvent [ M ] ], n )
5756 for i := 0 ; i < n ; i ++ {
58- iterators [i ], generators [i ] = NewAsyncIteratorPair [* AgentEvent ]()
57+ iterators [i ], generators [i ] = NewAsyncIteratorPair [* TypedAgentEvent [ M ] ]()
5958 }
6059
6160 go func () {
@@ -71,7 +70,7 @@ func copyEventIterator(iter *AsyncIterator[*AgentEvent], n int) []*AsyncIterator
7170 break
7271 }
7372 for i := 0 ; i < n - 1 ; i ++ {
74- generators [i ].Send (copyAgentEvent (event ))
73+ generators [i ].Send (copyTypedAgentEvent (event ))
7574 }
7675 generators [n - 1 ].Send (event )
7776 }
@@ -88,7 +87,7 @@ func copyAgentCallbackOutput(out *AgentCallbackOutput, n int) []*AgentCallbackOu
8887 }
8988 return result
9089 }
91- iters := copyEventIterator (out .Events , n )
90+ iters := copyTypedEventIterator (out .Events , n )
9291 result := make ([]* AgentCallbackOutput , n )
9392 for i , iter := range iters {
9493 result [i ] = & AgentCallbackOutput {Events : iter }
@@ -135,91 +134,55 @@ func getAgentType(agent Agent) string {
135134 return ""
136135}
137136
138- // AgenticCallbackInput represents the input passed to agentic agent callbacks during OnStart.
139- // Use ConvAgenticCallbackInput to safely convert from callbacks.CallbackInput.
140- type AgenticCallbackInput struct {
137+ // TypedAgentCallbackInput represents the input passed to typed agent callbacks during OnStart.
138+ // Use ConvTypedCallbackInput to safely convert from callbacks.CallbackInput.
139+ type TypedAgentCallbackInput [ M messageType ] struct {
141140 // Input contains the agent input for a new run. Nil when resuming.
142- Input * TypedAgentInput [* schema. AgenticMessage ]
141+ Input * TypedAgentInput [M ]
143142 // ResumeInfo contains resume information when resuming from an interrupt. Nil for new runs.
144143 ResumeInfo * ResumeInfo
145144}
146145
147- // AgenticCallbackOutput represents the output passed to agentic agent callbacks during OnEnd.
148- // Use ConvAgenticCallbackOutput to safely convert from callbacks.CallbackOutput.
146+ // TypedAgentCallbackOutput represents the output passed to typed agent callbacks during OnEnd.
147+ // Use ConvTypedCallbackOutput to safely convert from callbacks.CallbackOutput.
149148//
150149// Important: The Events iterator should be consumed asynchronously to avoid blocking
151150// the agent execution. Each callback handler receives an independent copy of the iterator.
152- type AgenticCallbackOutput struct {
153- // Events provides a stream of agentic agent events. Each handler receives its own copy.
154- Events * AsyncIterator [* TypedAgentEvent [* schema. AgenticMessage ]]
151+ type TypedAgentCallbackOutput [ M messageType ] struct {
152+ // Events provides a stream of agent events. Each handler receives its own copy.
153+ Events * AsyncIterator [* TypedAgentEvent [M ]]
155154}
156155
157- // ConvAgenticCallbackInput converts a callbacks.CallbackInput to *AgenticCallbackInput .
156+ // ConvTypedCallbackInput converts a callbacks.CallbackInput to *TypedAgentCallbackInput[M] .
158157// Returns nil if the input is not of the expected type.
159- func ConvAgenticCallbackInput (input callbacks.CallbackInput ) * AgenticCallbackInput {
160- if v , ok := input .(* AgenticCallbackInput ); ok {
158+ func ConvTypedCallbackInput [ M messageType ] (input callbacks.CallbackInput ) * TypedAgentCallbackInput [ M ] {
159+ if v , ok := input .(* TypedAgentCallbackInput [ M ] ); ok {
161160 return v
162161 }
163162 return nil
164163}
165164
166- // ConvAgenticCallbackOutput converts a callbacks.CallbackOutput to *AgenticCallbackOutput .
165+ // ConvTypedCallbackOutput converts a callbacks.CallbackOutput to *TypedAgentCallbackOutput[M] .
167166// Returns nil if the output is not of the expected type.
168- func ConvAgenticCallbackOutput (output callbacks.CallbackOutput ) * AgenticCallbackOutput {
169- if v , ok := output .(* AgenticCallbackOutput ); ok {
167+ func ConvTypedCallbackOutput [ M messageType ] (output callbacks.CallbackOutput ) * TypedAgentCallbackOutput [ M ] {
168+ if v , ok := output .(* TypedAgentCallbackOutput [ M ] ); ok {
170169 return v
171170 }
172171 return nil
173172}
174173
175- func copyAgenticEventIterator (iter * AsyncIterator [* TypedAgentEvent [* schema.AgenticMessage ]], n int ) []* AsyncIterator [* TypedAgentEvent [* schema.AgenticMessage ]] {
176- if n <= 0 {
177- return nil
178- }
179- if n == 1 {
180- return []* AsyncIterator [* TypedAgentEvent [* schema.AgenticMessage ]]{iter }
181- }
182-
183- iterators := make ([]* AsyncIterator [* TypedAgentEvent [* schema.AgenticMessage ]], n )
184- generators := make ([]* AsyncGenerator [* TypedAgentEvent [* schema.AgenticMessage ]], n )
185- for i := 0 ; i < n ; i ++ {
186- iterators [i ], generators [i ] = NewAsyncIteratorPair [* TypedAgentEvent [* schema.AgenticMessage ]]()
187- }
188-
189- go func () {
190- defer func () {
191- for _ , g := range generators {
192- g .Close ()
193- }
194- }()
195-
196- for {
197- event , ok := iter .Next ()
198- if ! ok {
199- break
200- }
201- for i := 0 ; i < n - 1 ; i ++ {
202- generators [i ].Send (copyAgenticEvent (event ))
203- }
204- generators [n - 1 ].Send (event )
205- }
206- }()
207-
208- return iterators
209- }
210-
211- func copyAgenticCallbackOutput (out * AgenticCallbackOutput , n int ) []* AgenticCallbackOutput {
174+ func copyTypedCallbackOutput [M messageType ](out * TypedAgentCallbackOutput [M ], n int ) []* TypedAgentCallbackOutput [M ] {
212175 if out == nil || out .Events == nil {
213- result := make ([]* AgenticCallbackOutput , n )
176+ result := make ([]* TypedAgentCallbackOutput [ M ] , n )
214177 for i := 0 ; i < n ; i ++ {
215178 result [i ] = out
216179 }
217180 return result
218181 }
219- iters := copyAgenticEventIterator (out .Events , n )
220- result := make ([]* AgenticCallbackOutput , n )
182+ iters := copyTypedEventIterator (out .Events , n )
183+ result := make ([]* TypedAgentCallbackOutput [ M ] , n )
221184 for i , iter := range iters {
222- result [i ] = & AgenticCallbackOutput {Events : iter }
185+ result [i ] = & TypedAgentCallbackOutput [ M ] {Events : iter }
223186 }
224187 return result
225188}
@@ -228,7 +191,7 @@ func initAgenticCallbacks(ctx context.Context, agentName, agentType string, opts
228191 ri := & callbacks.RunInfo {
229192 Name : agentName ,
230193 Type : agentType ,
231- Component : ComponentOfAgentic ,
194+ Component : ComponentOfAgenticAgent ,
232195 }
233196
234197 o := getCommonOptions (nil , opts ... )
0 commit comments