Skip to content

Advanced Core Embedding

Integration runtime capabilities: config, registry, run engine, and channel runners.

Advanced Core Embedding

This page only covers capabilities provided by the integration package.

What integration Provides

  • integration.DefaultConfig() / integration.Config.Set(...)
  • integration.New(cfg)
  • rt.NewRegistry()
  • rt.NewRunEngine(...)
  • rt.NewRunEngineWithRegistry(...)
  • rt.RunTask(...)
  • rt.RequestTimeout()
  • rt.NewTelegramBot(...)
  • rt.NewSlackBot(...)

Config Layer (Inside integration.Config)

  • Overrides + Set(key, value): override Viper keys.
  • Features: toggle built-in runtime wiring (PlanTool, Guard, Skills).
  • BuiltinToolNames: built-in tool whitelist (empty = all built-ins).
  • Inspect: prompt/request dump behavior.
go
cfg := integration.DefaultConfig()
cfg.Set("llm.provider", "openai")
cfg.Set("llm.model", "gpt-5.4")
cfg.Set("llm.api_key", os.Getenv("OPENAI_API_KEY"))
cfg.Features.Skills = true
cfg.BuiltinToolNames = []string{"read_file", "url_fetch", "todo_update"}

Registry and Custom Tools

integration lets you extend runtime registry before engine creation.

Runnable Example (Custom Tool + integration Runtime)

go
package main

import (
  "context"
  "encoding/json"
  "fmt"
  "os"
  "strings"

  "github.com/quailyquaily/mistermorph/agent"
  "github.com/quailyquaily/mistermorph/integration"
)

type EchoTool struct{}

func (t *EchoTool) Name() string { return "echo_text" }

func (t *EchoTool) Description() string {
  return "Echoes input text as JSON."
}

func (t *EchoTool) ParameterSchema() string {
  return `{
  "type": "object",
  "properties": {
    "text": {"type": "string", "description": "Text to echo."}
  },
  "required": ["text"]
}`
}

func (t *EchoTool) Execute(_ context.Context, params map[string]any) (string, error) {
  text, _ := params["text"].(string)
  text = strings.TrimSpace(text)
  if text == "" {
    return "", fmt.Errorf("text is required")
  }
  b, _ := json.Marshal(map[string]any{"text": text})
  return string(b), nil
}

func main() {
  cfg := integration.DefaultConfig()
  cfg.Set("llm.provider", "openai")
  cfg.Set("llm.model", "gpt-5.4")
  cfg.Set("llm.api_key", os.Getenv("OPENAI_API_KEY"))

  rt := integration.New(cfg)
  reg := rt.NewRegistry()
  reg.Register(&EchoTool{})

  task := "Call tool echo_text with text 'hello from tool', then answer with that text."

  prepared, err := rt.NewRunEngineWithRegistry(context.Background(), task, reg)
  if err != nil {
    panic(err)
  }
  defer prepared.Cleanup()

  final, _, err := prepared.Engine.Run(context.Background(), task, agent.RunOptions{Model: prepared.Model})
  if err != nil {
    panic(err)
  }

  fmt.Println(final.Output)
}

Run APIs

Prepared Engine API

go
prepared, err := rt.NewRunEngine(context.Background(), task)
if err != nil {
  panic(err)
}
defer prepared.Cleanup()

final, _, err := prepared.Engine.Run(context.Background(), task, agent.RunOptions{
  Model: prepared.Model,
})

Why Use Prepared Engine API

  • Controlled lifecycle: you decide exactly when to call Cleanup().
  • Reusability: reuse the same prepared.Engine for multiple runs.
  • Per-run flexibility: pass different RunOptions on each run.
  • Better orchestration: direct access to prepared.Model and Engine for your session/scheduler layer.

Convenience API

go
final, runCtx, err := rt.RunTask(context.Background(), task, agent.RunOptions{})
_ = final
_ = runCtx
_ = err

Inspect and Runtime Diagnostics

go
cfg.Inspect.Prompt = true
cfg.Inspect.Request = true
cfg.Inspect.DumpDir = "./dump"

Telegram Channel Integration (Advanced)

go
tg, _ := rt.NewTelegramBot(integration.TelegramOptions{BotToken: os.Getenv("MISTER_MORPH_TELEGRAM_BOT_TOKEN")})
_ = tg

Slack Channel Integration (Optional)

go
sl, _ := rt.NewSlackBot(integration.SlackOptions{
  BotToken: os.Getenv("MISTER_MORPH_SLACK_BOT_TOKEN"),
  AppToken: os.Getenv("MISTER_MORPH_SLACK_APP_TOKEN"),
})
_ = sl

Out of Scope for This Page

Low-level engine customization is documented in Agent-Level Customization.