Resume only the task that owns the event
You let input-required and terminal events resume only their identity-scoped owning continuation. Recorded envelopes make that boundary testable without a live server.
Worked example
See the idea in context
target := ax.AxEventTarget{
ID: "reindex-flow", RetrySafety: "idempotent",
WaitFor: []map[string]ax.Value{{
"kind": "mcp.task", "value": "taskKey",
"metadata": map[string]ax.Value{"taskId": taskID},
}},
MapInput: func(event ax.AxEventEnvelope, continuation *ax.AxEventContinuation) (ax.Value, error) {
if continuation != nil {
return map[string]ax.Value{"taskId": continuation.Metadata["taskId"]}, nil
}
return map[string]ax.Value{"taskId": event.Data.(map[string]ax.Value)["taskId"]}, nil
},
Invoke: invokeFlow,
}
routes := []ax.AxEventRoute{
{ID: "task-start", Action: "wake", TargetID: "reindex-flow", Match: map[string]ax.Value{"types": ax.Array("app.task.started")}},
{ID: "task-resume", Action: "resume", TargetID: "reindex-flow", Match: map[string]ax.Value{"types": ax.Array("mcp.task.status")}},
}Run itIn your own project
go get github.com/ax-llm/ax/packages/go
package main
import (
"context"
"fmt"
"os"
axllm "github.com/ax-llm/ax/packages/go"
)
func main() {
client := axllm.NewAI("openai", map[string]axllm.Value{"apiKey": os.Getenv("OPENAI_API_KEY")})
classify := axllm.NewAx("review:string -> sentiment:class \"positive, negative, neutral\"", nil)
result, err := classify.Forward(context.Background(), client, map[string]axllm.Value{
"review": "Useful and boring in the best way."
}, nil)
if err != nil {
panic(err)
}
fmt.Println("sentiment:", result.(map[string]axllm.Value)["sentiment"])
}Set OPENAI_APIKEY in your environment before running provider-backed code.
From a clone of the ax repo:
npm run example -- go src/examples/go/mcp/resource_wake_agent.goActive practice
Answer 2 in a row to learn this · attempt 1