From 39c3c47ea2ea57b651cafd7586aff951346d555e Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 18 Oct 2026 02:32:30 +1100 Subject: [PATCH] feat(gateway): workflow and integration tools for chat and Kit harnesses alike --- internal/app/archiegateway/chat_setup.go | 2 - internal/app/archiegateway/gateway_runtime.go | 1 - internal/app/archiegateway/tools.go | 34 +++++++ internal/gateway/integration_tools.go | 88 +++++++++++++++++++ internal/gateway/turn.go | 11 +-- .../controlplanerpc/workflows.go | 9 ++ 6 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 internal/gateway/integration_tools.go diff --git a/internal/app/archiegateway/chat_setup.go b/internal/app/archiegateway/chat_setup.go index b13e06a04..e4fa7a0ae 100644 --- a/internal/app/archiegateway/chat_setup.go +++ b/internal/app/archiegateway/chat_setup.go @@ -51,7 +51,6 @@ type chatSetup struct { ChatTaskLogs gateway.ChatTaskLogReader ChatTaskActor gateway.ChatTaskActor DefaultChatIdentity string - Workflows gateway.WorkflowSource // Bus carries primary-input events: a completed // chat turn is published here so input-driven curators can wake. Nil // disables turn events (tests, minimal setups). @@ -139,7 +138,6 @@ func newChatTurnRunner( TaskLogs: s.ChatTaskLogs, TaskActor: s.ChatTaskActor, TaskIdentity: s.DefaultChatIdentity, - Workflows: s.Workflows, Bus: s.Bus, BotUser: cfg.BotUser, Channel: channel, diff --git a/internal/app/archiegateway/gateway_runtime.go b/internal/app/archiegateway/gateway_runtime.go index 0ad67e794..5eec330f3 100644 --- a/internal/app/archiegateway/gateway_runtime.go +++ b/internal/app/archiegateway/gateway_runtime.go @@ -206,7 +206,6 @@ func (b *server) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskAct ChatTaskLogs: chatTaskLogReaderAdapter{tasks: b.stateStore.TaskByID, taskLogs: b.stateStore}, ChatTaskActor: actor, DefaultChatIdentity: b.defaultChatIdentity, - Workflows: controlplanerpc.NewWorkflows(b.stateStore.ControlPlane()), Bus: b.bus, Log: b.log, MemoryEngine: b.memoryStore(), MemoryWriter: b.memoryWriter(), diff --git a/internal/app/archiegateway/tools.go b/internal/app/archiegateway/tools.go index ee4f44b76..385620b17 100644 --- a/internal/app/archiegateway/tools.go +++ b/internal/app/archiegateway/tools.go @@ -11,6 +11,11 @@ import ( "github.com/samcharles93/archie-core/internal/agentexec/modelloop" "github.com/samcharles93/archie-core/internal/config" + "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/eventtype" + "github.com/samcharles93/archie-core/internal/gateway" + "github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc" + "github.com/samcharles93/archie-core/internal/infrastructure/staterpc" "github.com/samcharles93/archie-core/internal/infrastructure/taskmcp" "github.com/samcharles93/archie-core/internal/plugin" "github.com/samcharles93/archie-core/internal/tools/mcp" @@ -86,6 +91,35 @@ func (b *server) registerStandaloneTools() { } b.registerMinimaxTool(cfg, log) + b.registerWorkflowTools() +} + +// registerWorkflowTools puts the workflow and integration tools in the shared +// registry, so chat turns and Kit harnesses (through the task-tool RPCs) both +// reach them, each in its own caller's org. +func (b *server) registerWorkflowTools() { + workflows := controlplanerpc.NewWorkflows(b.stateStore.ControlPlane()) + entries := append(gateway.WorkflowTools(workflows), gateway.IntegrationTools(integrationSource{Workflows: workflows, store: b.stateStore})...) + for _, entry := range entries { + if err := b.toolReg.Register(entry); err != nil { + b.log.Warn("workflow tool registration failed", "tool", entry.Name, "err", err) + } + } +} + +// integrationSource reads settings through the control plane and event types +// and bindings through the State Store. +type integrationSource struct { + controlplanerpc.Workflows + store *staterpc.Client +} + +func (s integrationSource) EventTypes(ctx context.Context) ([]eventtype.EventType, error) { + return s.store.ListEventTypes(ctx) +} + +func (s integrationSource) Bindings(ctx context.Context) ([]binding.Binding, error) { + return s.store.ListBindings(ctx) } func (b *server) registerWebFetchTool(cfg config.Config) { diff --git a/internal/gateway/integration_tools.go b/internal/gateway/integration_tools.go new file mode 100644 index 000000000..a7f75331f --- /dev/null +++ b/internal/gateway/integration_tools.go @@ -0,0 +1,88 @@ +package gateway + +import ( + "context" + "encoding/json" + "fmt" + "slices" + "strings" + + "github.com/samcharles93/archie-core/internal/domain/binding" + "github.com/samcharles93/archie-core/internal/domain/eventtype" + "github.com/samcharles93/archie-core/internal/tools" +) + +// IntegrationSource is what the integration tools read, in the caller's org. +type IntegrationSource interface { + Resource(ctx context.Context, kind string) (json.RawMessage, error) + EventTypes(ctx context.Context) ([]eventtype.EventType, error) + Bindings(ctx context.Context) ([]binding.Binding, error) +} + +// readableKinds are the settings that shape what a workflow can do and what +// starts it. Provider, channel and connection settings are left out: they +// carry endpoints and secret references an agent has no use for. +var readableKinds = []string{ + "workflow-execution-settings", "workflow-enablement", "agent-profiles", "skills", + "schedules", "eda-playbooks", "credential-bindings", "identity-grants", +} + +// IntegrationTools returns read-only tools for investigating what starts +// workflows and how they can be customised. Nil source registers none. +func IntegrationTools(source IntegrationSource) []tools.ToolEntry { + if source == nil { + return nil + } + return []tools.ToolEntry{ + { + Name: "settings_get", + Toolset: "workflows", + Description: "Return one settings document as JSON. Kinds: " + strings.Join(readableKinds, ", ") + ".", + Classification: tools.ClassIdempotent, + Schema: tools.JSONSchema{ + "type": "object", + "properties": map[string]any{"kind": map[string]any{"type": "string", "enum": readableKinds}}, + "required": []any{"kind"}, + }, + Handler: func(ctx context.Context, input map[string]any) (any, error) { + kind := asString(input["kind"]) + if !slices.Contains(readableKinds, kind) { + return nil, fmt.Errorf("settings_get: %q is not readable; use one of %s", kind, strings.Join(readableKinds, ", ")) + } + value, err := source.Resource(ctx, kind) + if err != nil { + return nil, fmt.Errorf("settings_get: %w", err) + } + return value, nil + }, + }, + { + Name: "event_types_list", + Toolset: "workflows", + Description: "List the named event types: each one's source, the rule that recognises it and the fields its payload carries.", + Classification: tools.ClassIdempotent, + Schema: tools.JSONSchema{"type": "object", "properties": map[string]any{}}, + Handler: func(ctx context.Context, _ map[string]any) (any, error) { + types, err := source.EventTypes(ctx) + if err != nil { + return nil, fmt.Errorf("event_types_list: %w", err) + } + return types, nil + }, + }, + { + Name: "bindings_list", + Toolset: "workflows", + Description: "List the bindings that start workflows from events: what each matches, its filter and the workflow it runs.", + Classification: tools.ClassIdempotent, + Schema: tools.JSONSchema{"type": "object", "properties": map[string]any{}}, + Handler: func(ctx context.Context, _ map[string]any) (any, error) { + bindings, err := source.Bindings(ctx) + if err != nil { + return nil, fmt.Errorf("bindings_list: %w", err) + } + return bindings, nil + }, + }, + } +} diff --git a/internal/gateway/turn.go b/internal/gateway/turn.go index 1f0848e90..946862957 100644 --- a/internal/gateway/turn.go +++ b/internal/gateway/turn.go @@ -102,12 +102,10 @@ type TurnRunnerConfig struct { TaskLogs ChatTaskLogReader TaskActor ChatTaskActor TaskIdentity string - // Workflows backs the workflow read and validate tools. Nil omits them. - Workflows WorkflowSource - Bus TurnEventPublisher - BotUser string - Channel string - Operator string + Bus TurnEventPublisher + BotUser string + Channel string + Operator string // Workspace is the directory the chat agent's file and shell tools are // rooted at (chat.workspace). Passed into the prompt's block. Workspace string @@ -308,7 +306,6 @@ func (r *TurnRunner) prepareTurn(ctx context.Context, sessionID string, in Inbou // UI only: a non-web channel has no dashboard to point at. extraTools = append(extraTools, PageIndexTools(r.Channel)...) extraTools = append(extraTools, MemoryTools(r.MemoryWriter, subject)...) - extraTools = append(extraTools, WorkflowTools(r.Workflows)...) // The question tool is per-turn: it exists only when this turn's channel // adapter can carry a clarify/picker interaction (see WithInteractive). extraTools = append(extraTools, InteractiveTools(ctx)...) diff --git a/internal/infrastructure/controlplanerpc/workflows.go b/internal/infrastructure/controlplanerpc/workflows.go index 52f4d8039..dfd311f22 100644 --- a/internal/infrastructure/controlplanerpc/workflows.go +++ b/internal/infrastructure/controlplanerpc/workflows.go @@ -128,3 +128,12 @@ func (w Workflows) PutDraft(ctx context.Context, id, src string) error { } return nil } + +// Resource returns one control-plane document's value in the caller's org. +func (w Workflows) Resource(ctx context.Context, kind string) (json.RawMessage, error) { + response, err := w.rpc.Query(ctx, &pb.QueryRequest{Kind: kind}) + if err != nil { + return nil, fmt.Errorf("%w: %w", ErrUnavailable, err) + } + return response.GetResource().GetValueJson(), nil +}