Dispatch returns a StepFunc that hands the current state Data (as the message) to a registered agent's Agent.Chat endpoint and stores the reply as the new Data.
(name string)
| 267 | // message) to a registered agent's Agent.Chat endpoint and stores the |
| 268 | // reply as the new Data. |
| 269 | func Dispatch(name string) StepFunc { |
| 270 | return func(ctx context.Context, in State) (State, error) { |
| 271 | cl := client.DefaultClient |
| 272 | if d := depsFrom(ctx); d != nil && d.client != nil { |
| 273 | cl = d.client |
| 274 | } |
| 275 | info, _ := ai.RunInfoFrom(ctx) |
| 276 | body, _ := json.Marshal(map[string]string{"message": in.String(), "parent_id": info.RunID}) |
| 277 | req := cl.NewRequest(name, "Agent.Chat", &codecbytes.Frame{Data: body}) |
| 278 | var rsp codecbytes.Frame |
| 279 | if err := cl.Call(ctx, req, &rsp); err != nil { |
| 280 | return in, err |
| 281 | } |
| 282 | var out struct { |
| 283 | Reply string `json:"reply"` |
| 284 | } |
| 285 | _ = json.Unmarshal(rsp.Data, &out) |
| 286 | in.Data = []byte(out.Reply) |
| 287 | return in, nil |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // A2A returns a StepFunc that calls a remote agent over the A2A protocol |
| 292 | // by URL — the cross-framework counterpart to Dispatch. It sends the |
searching dependent graphs…