feat: read agent_id from ctx (SDK now plumbs it)
Plexum-sdk-go now unpacks `_meta.agent_id` from host's MCP tools/call
frames into the ctx. Plugin reads it via plugin.AgentIDFromContext
and uses it for backend api-key resolution (agentKeys map lookup +
bearer token) and HF on_call pre-check.
config.defaultAgentID demoted from "v1 stop-gap for the missing SDK
plumbing" to "fallback for operator-driven plugin-call". Normal turn
loops carry the real caller id through ctx now; defaultAgentID only
fires on host-driven dispatch paths.
Also: log every CallTool dispatch with {tool, agent_id} at info level
so operators can see which agent is hitting which tool without
debug-level chatter.
E2E in sim: PLEXUM_ECHO_FORCE_TOOL_USE drives echo provider →
dialectic_list_topics dispatched via host → plugin sees
agent_id=test-agent in ctx + logs it correctly.
This commit is contained in:
@@ -56,9 +56,14 @@ func (p *dialecticPlugin) Init(ctx context.Context, host sdkplugin.HostAPI) erro
|
||||
Config: p.cfg,
|
||||
Host: host,
|
||||
AgentIDFromCtx: func(ctx context.Context) string {
|
||||
// v1: SDK doesn't surface the calling agent on tool ctx.
|
||||
// Fall back to the per-claw default. Multi-agent claws will
|
||||
// need SDK ctx plumbing — tracked upstream.
|
||||
// Host attaches the caller agent id via tools/call
|
||||
// `_meta.agent_id`; SDK unpacks it into ctx.
|
||||
if id := sdkplugin.AgentIDFromContext(ctx); id != "" {
|
||||
return id
|
||||
}
|
||||
// Fallback for host paths that don't carry an agent
|
||||
// (CLI plugin-call against this plugin from an operator
|
||||
// debugging the deployment). Empty when not set.
|
||||
return p.cfg.DefaultAgentID
|
||||
},
|
||||
}
|
||||
@@ -66,6 +71,10 @@ func (p *dialecticPlugin) Init(ctx context.Context, host sdkplugin.HostAPI) erro
|
||||
}
|
||||
|
||||
func (p *dialecticPlugin) CallTool(ctx context.Context, name string, input json.RawMessage) (sdkplugin.ToolResult, error) {
|
||||
p.host.Log("info", "tools/call dispatched", map[string]any{
|
||||
"tool": name,
|
||||
"agent_id": sdkplugin.AgentIDFromContext(ctx),
|
||||
})
|
||||
return tools.Dispatch(ctx, p.deps, name, input)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user