MCPcopy
hub / github.com/micro/go-micro / Dispatch

Function Dispatch

flow/steps.go:269–289  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

267// message) to a registered agent's Agent.Chat endpoint and stores the
268// reply as the new Data.
269func 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

Callers 3

FlowDispatchFunction · 0.92
dispatchNotifyStepFunction · 0.92

Calls 7

RunInfoFromFunction · 0.92
depsFromFunction · 0.85
MarshalMethod · 0.65
StringMethod · 0.65
NewRequestMethod · 0.65
CallMethod · 0.65
UnmarshalMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…