mirror of
https://github.com/go-micro/go-micro.git
synced 2026-06-15 19:35:13 +02:00
e416ea4a75
* docs: map go-micro onto Anthropic's workflows-vs-agents taxonomy - new guide 'Agents and Workflows': adopts Anthropic's Building Effective Agents vocabulary — workflow (predefined path) = flow, agent (dynamic self-direction) = agent — maps the augmented-LLM building block and the five workflow patterns onto go-micro, and shows routing (chat router) and orchestrator-workers (conductor + plan/delegate) are already native. - flow package doc reframed as a workflow (predefined path) per the same taxonomy, with guidance on flow vs agent. - nav + README link the new guide. * feat: agent guardrails — step limit and tool approval hook Anthropic's Building Effective Agents stresses stopping conditions and human-in-the-loop checkpoints for autonomous agents. Add both as plain options enforced at the tool-handler choke point — no provider changes, no new abstraction: - MaxSteps(n): bound tool executions per Ask; beyond the limit, actions are refused and the model is told to stop and summarize. - ApproveTool(fn): gate each action before it runs; returning false blocks it and surfaces the reason to the model. The internal plan tool is never gated. Exposed at the micro package (AgentMaxSteps, AgentApproveTool, ApproveFunc). Tests cover the limit, blocking, and that plan is not gated. Guardrails section of the agents-and-workflows guide updated from 'active work' to documented options. * feat: flow can dispatch to an agent (flow triggers, agent reasons) Unify the engine without collapsing the workflow/agent distinction. A Flow with Agent set hands each event's rendered prompt to a named registered agent over RPC (Agent.Chat) instead of running its own LLM step — so the workflow stays the deterministic trigger and the agent is the reasoning engine, with its plan, delegate, memory, and guardrails. A plain flow is unchanged (single augmented-LLM step). - flow.Agent(name) / micro.FlowAgent(name); flow stores the client and skips model setup when dispatching. - test: dispatch routes to comms.Agent.Chat with the rendered prompt and records the reply. - guide: 'Flow triggers, Agent reasons' section. --------- Co-authored-by: Claude <noreply@anthropic.com>
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package flow
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"go-micro.dev/v5/client"
|
|
codecbytes "go-micro.dev/v5/codec/bytes"
|
|
)
|
|
|
|
// fakeClient embeds the default client (so NewRequest works) and
|
|
// overrides Call with a test-supplied function.
|
|
type fakeClient struct {
|
|
client.Client
|
|
callFn func(req client.Request, rsp interface{}) error
|
|
}
|
|
|
|
func (c *fakeClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
|
return c.callFn(req, rsp)
|
|
}
|
|
|
|
// A flow with Agent set hands the rendered prompt to that agent's
|
|
// Agent.Chat endpoint over RPC and records its reply — it does not run
|
|
// its own model.
|
|
func TestExecuteDispatchesToAgent(t *testing.T) {
|
|
f := New("welcome", Agent("comms"), Prompt("welcome {{.Data}}"))
|
|
|
|
var svc, ep string
|
|
f.client = &fakeClient{
|
|
Client: client.DefaultClient,
|
|
callFn: func(req client.Request, rsp interface{}) error {
|
|
svc, ep = req.Service(), req.Endpoint()
|
|
frame := rsp.(*codecbytes.Frame)
|
|
frame.Data = []byte(`{"reply":"welcomed bob","agent":"comms"}`)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
if err := f.Execute(context.Background(), "bob"); err != nil {
|
|
t.Fatalf("Execute: %v", err)
|
|
}
|
|
|
|
if svc != "comms" || ep != "Agent.Chat" {
|
|
t.Errorf("dispatched to %s.%s, want comms.Agent.Chat", svc, ep)
|
|
}
|
|
|
|
results := f.Results()
|
|
if len(results) != 1 {
|
|
t.Fatalf("got %d results, want 1", len(results))
|
|
}
|
|
if results[0].Reply != "welcomed bob" {
|
|
t.Errorf("result reply = %q, want %q", results[0].Reply, "welcomed bob")
|
|
}
|
|
if results[0].Prompt != "welcome bob" {
|
|
t.Errorf("rendered prompt = %q, want %q", results[0].Prompt, "welcome bob")
|
|
}
|
|
}
|