MCPcopy Create free account
hub / github.com/astercloud/aster / RunStream

Method RunStream

pkg/workflow/workflow_agent.go:213–267  ·  view source on GitHub ↗

RunStream 流式运行 WorkflowAgent

(ctx context.Context, input string)

Source from the content-addressed store, hash-verified

211
212// RunStream 流式运行 WorkflowAgent
213func (wa *WorkflowAgent) RunStream(ctx context.Context, input string) <-chan AgentStreamEvent {
214 eventChan := make(chan AgentStreamEvent, 100)
215
216 go func() {
217 defer close(eventChan)
218
219 eventChan <- AgentStreamEvent{
220 Type: AgentEventStart,
221 Timestamp: time.Now(),
222 Data: map[string]any{"input": input},
223 }
224
225 workflowInput := &WorkflowInput{Input: input}
226 reader := wa.workflow.Execute(ctx, workflowInput)
227 for {
228 event, err := reader.Recv()
229 if err != nil {
230 if errors.Is(err, io.EOF) {
231 break
232 }
233 eventChan <- AgentStreamEvent{
234 Type: AgentEventError,
235 Timestamp: time.Now(),
236 Error: err,
237 }
238 continue
239 }
240
241 eventChan <- AgentStreamEvent{
242 Type: AgentEventWorkflowEvent,
243 Timestamp: time.Now(),
244 Data: map[string]any{"workflow_event": event},
245 }
246
247 if event.Type == EventWorkflowCompleted {
248 if data, ok := event.Data.(map[string]any); ok {
249 if output, ok := data["output"]; ok {
250 eventChan <- AgentStreamEvent{
251 Type: AgentEventResponse,
252 Timestamp: time.Now(),
253 Data: map[string]any{"response": output},
254 }
255 }
256 }
257 }
258 }
259
260 eventChan <- AgentStreamEvent{
261 Type: AgentEventComplete,
262 Timestamp: time.Now(),
263 }
264 }()
265
266 return eventChan
267}
268
269// ===== Types =====
270

Callers 2

testWorkflowAgentFunction · 0.95
AgenticExecuteStreamMethod · 0.80

Calls 2

RecvMethod · 0.80
ExecuteMethod · 0.65

Tested by

no test coverage detected