Skip to content

Integration API

Exported functions, methods, struct fields, parameters, return values, and purpose of the integration package.

Integration API

This page lists the exported API of github.com/quailyquaily/mistermorph/integration.

If you mainly want to see how to configure integration.Config, use PreparedRun, or connect Telegram / Slack, start with Create Your Own AI Agent: Advanced.

Top-Level Functions

ApplyViperDefaults(v *viper.Viper)

ItemValue
Parametersv *viper.Viper: target viper instance; if nil, it falls back to viper.GetViper()
Returnsnone
DescriptionWrites the shared default config used by both integration and first-party runtimes into a viper instance. You only need this if your host app also organizes config through viper.

DefaultFeatures() Features

ItemValue
Parametersnone
Returnsintegration.Features
DescriptionReturns the default feature switches. PlanTool, Guard, and Skills are currently enabled by default.

DefaultConfig() Config

ItemValue
Parametersnone
Returnsintegration.Config
DescriptionReturns the default config. Overrides starts as an empty map, Features comes from DefaultFeatures(), and Inspect is the zero value.

New(cfg Config) *Runtime

ItemValue
Parameterscfg integration.Config: explicit config assembled by the host program
Returns*integration.Runtime
DescriptionBuilds a reusable runtime and snapshots defaults plus overrides during construction.

type Features struct

FieldTypeDescription
PlanToolboolWhether to register runtime helper tooling related to plan_create.
GuardboolWhether to enable guard inside the runtime.
SkillsboolWhether to enable skill loading during prompt construction.

type InspectOptions struct

FieldTypeDescription
PromptboolWhether to dump prompts to disk.
RequestboolWhether to dump requests / responses to disk.
DumpDirstringOutput directory for dumps.
ModestringInspect mode name used to distinguish output.
TimestampFormatstringTimestamp format used in file names.

type Config struct

FieldTypeDescription
Overridesmap[string]anyFinal override map written using viper keys; highest precedence.
Featuresintegration.FeaturesControls which runtime capabilities get wired in.
PromptBlocks[]stringStatic blocks appended under system prompt Additional Policies.
BuiltinToolNames[]stringBuilt-in tool allowlist; empty means enable all.
Inspectintegration.InspectOptionsPrompt / request dump options for debugging.

(*Config).Set(key string, value any)

ItemValue
Parameterskey string: viper config key; value any: override value
Returnsnone
DescriptionWrites one override entry into Overrides. Blank keys are ignored.

(*Config).AddPromptBlock(content string)

ItemValue
Parameterscontent string: prompt block text to append
Returnsnone
DescriptionAppends one static prompt block. Blank strings are ignored, and blocks are applied to the runtime in order.

Runtime and Execution

type Runtime struct

Runtime is the main entry point for third-party embedding. It does not expose fields directly; it mainly works through methods.

type PreparedRun struct

FieldTypeDescription
Engine*agent.EnginePrepared engine ready to run.
ModelstringModel name resolved from the current main route.
Cleanupfunc() errorReleases temporary resources such as inspect output or MCP wiring.

type LLMProfile struct

FieldTypeDescription
NamestringProfile name.
ProviderstringResolved provider name.
ModelNamestringResolved model name.
APIBasestringResolved API base when present.

type LLMProfileCandidate struct

FieldTypeDescription
LLMProfileintegration.LLMProfileCandidate profile info.
WeightintCandidate weight from llm.routes.main_loop.candidates.

type LLMProfileSelection struct

FieldTypeDescription
Modestringauto or manual.
ManualProfilestringManual override target when Mode is manual.
RouteTypestringprofile or candidates.
Current*integration.LLMProfileCurrent resolved profile when the strategy is a single profile.
Candidates[]integration.LLMProfileCandidateWeighted candidates when the strategy is candidates.
FallbackProfiles[]integration.LLMProfileFallback profiles resolved from the route.

(*Runtime).NewRegistry() *tools.Registry

ItemValue
Parametersnone
Returns*tools.Registry
DescriptionBuilds the default registry from the current runtime snapshot. This is usually where you start before adding custom tools.

(*Runtime).NewRunEngine(ctx context.Context, task string) (*PreparedRun, error)

ItemValue
Parametersctx context.Context: setup context; task string: current task text
Returns*integration.PreparedRun, error
DescriptionPrepares a reusable engine with the default registry.

(*Runtime).NewRunEngineWithRegistry(ctx context.Context, task string, baseReg *tools.Registry) (*PreparedRun, error)

ItemValue
Parametersctx context.Context: setup context; task string: current task text; baseReg *tools.Registry: base registry
Returns*integration.PreparedRun, error
DescriptionPrepares an engine on top of the registry you provide. If you want built-ins plus custom tools, call rt.NewRegistry() first and then register your additions.

(*Runtime).RunTask(ctx context.Context, task string, opts agent.RunOptions) (*agent.Final, *agent.Context, error)

ItemValue
Parametersctx context.Context: run context; task string: task text; opts agent.RunOptions: run options for this execution
Returns*agent.Final, *agent.Context, error
DescriptionOne-shot convenience entry point. It prepares an engine internally and calls Cleanup() automatically after execution.

(*Runtime).GetLLMProfileSelection() (LLMProfileSelection, error)

ItemValue
Parametersnone
Returnsintegration.LLMProfileSelection, error
DescriptionReturns the current main_loop selection view for this runtime instance. In candidates mode it reports the weighted strategy instead of forcing a single profile.

(*Runtime).ListLLMProfiles() ([]LLMProfile, error)

ItemValue
Parametersnone
Returns[]integration.LLMProfile, error
DescriptionLists all configured LLM profiles with name, provider, model_name, and optional api_base.

(*Runtime).SetLLMProfile(profileName string) error

ItemValue
ParametersprofileName string: profile name to force for main_loop
Returnserror
DescriptionSwitches this runtime instance to manual mode for main_loop. Other route purposes such as plan_create are unchanged.

(*Runtime).ResetLLMProfile()

ItemValue
Parametersnone
Returnsnone
DescriptionClears the manual main_loop override for this runtime instance and returns to the configured route policy.

(*Runtime).RequestTimeout() time.Duration

ItemValue
Parametersnone
Returnstime.Duration
DescriptionReturns the LLM request timeout resolved from the current runtime snapshot.

Channel Runner

type BotRunner interface

MethodParametersReturnsDescription
Runctx context.ContexterrorStarts a long-running channel bot.
ClosenoneerrorCloses the runner proactively.

type TelegramOptions struct

FieldTypeDescription
BotTokenstringTelegram bot token.
AllowedChatIDs[]int64Allowed chat whitelist.
PollTimeouttime.DurationTelegram polling timeout.
TaskTimeouttime.DurationPer-task run timeout.
MaxConcurrencyintMaximum concurrent task count.
GroupTriggerModestringGroup trigger mode.
AddressingConfidenceThresholdfloat64Addressing hit threshold.
AddressingInterjectThresholdfloat64Interject threshold.
Hooksintegration.TelegramHooksEvent callbacks.

type SlackOptions struct

FieldTypeDescription
BotTokenstringSlack bot token.
AppTokenstringSlack app token.
AllowedTeamIDs[]stringAllowed team whitelist.
AllowedChannelIDs[]stringAllowed channel whitelist.
TaskTimeouttime.DurationPer-task run timeout.
MaxConcurrencyintMaximum concurrent task count.
GroupTriggerModestringGroup trigger mode.
AddressingConfidenceThresholdfloat64Addressing hit threshold.
AddressingInterjectThresholdfloat64Interject threshold.
Hooksintegration.SlackHooksEvent callbacks.

type TelegramHooks struct

FieldTypeDescription
OnInboundfunc(TelegramInboundEvent)Triggered when an inbound event is received.
OnOutboundfunc(TelegramOutboundEvent)Triggered when an outbound event is emitted.
OnErrorfunc(TelegramErrorEvent)Runtime error event callback.

type SlackHooks struct

FieldTypeDescription
OnInboundfunc(SlackInboundEvent)Triggered when an inbound event is received.
OnOutboundfunc(SlackOutboundEvent)Triggered when an outbound event is emitted.
OnErrorfunc(SlackErrorEvent)Runtime error event callback.

(*Runtime).NewTelegramBot(opts TelegramOptions) (BotRunner, error)

ItemValue
Parametersopts integration.TelegramOptions
Returnsintegration.BotRunner, error
DescriptionBuilds a Telegram runner. Returns an error immediately if BotToken is empty.

(*Runtime).NewSlackBot(opts SlackOptions) (BotRunner, error)

ItemValue
Parametersopts integration.SlackOptions
Returnsintegration.BotRunner, error
DescriptionBuilds a Slack runner. Returns an error immediately if BotToken or AppToken is empty.

Event Alias Types

These exported aliases are mainly used in hook signatures:

  • TelegramInboundEvent
  • TelegramOutboundEvent
  • TelegramErrorEvent
  • SlackInboundEvent
  • SlackOutboundEvent
  • SlackErrorEvent

For most business logic, you only need to consume these event values inside Hooks; you do not need to manipulate the lower-level runtime directly.