feat(gateway): workflow and integration tools for chat and Kit harnesses alike
This commit is contained in:
1 parent
f5770fdc6e
commit
39c3c47ea2
6 files changed
+135
-10
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -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 <env> 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)...)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user