Skip to content

Integration API

integration パッケージの公開関数、メソッド、構造体フィールド、引数、戻り値、用途を一覧化する。

Integration API

このページでは github.com/quailyquaily/mistermorph/integration の公開 API をまとめます。

integration.Config の設定方法、PreparedRun の使い方、Telegram / Slack 接続を先に見たい場合は、自分の AI Agent を作る:上級編 を参照してください。

トップレベル関数

ApplyViperDefaults(v *viper.Viper)

項目内容
引数v *viper.Viper:デフォルト値を書き込む viper インスタンス。nil の場合は viper.GetViper() にフォールバック
戻り値なし
説明integration とファーストパーティ runtime で共有しているデフォルト設定を viper に書き込みます。ホストアプリ側も viper で設定管理している場合にだけ必要です。

DefaultFeatures() Features

項目内容
引数なし
戻り値integration.Features
説明デフォルトの feature フラグを返します。現在は PlanToolGuardSkills が有効です。

DefaultConfig() Config

項目内容
引数なし
戻り値integration.Config
説明デフォルト設定を返します。Overrides は空 map、FeaturesDefaultFeatures()Inspect はゼロ値です。

New(cfg Config) *Runtime

項目内容
引数cfg integration.Config:ホストプログラムが組み立てた明示設定
戻り値*integration.Runtime
説明再利用可能な runtime を構築し、生成時にデフォルト値と override をスナップショット化します。

設定関連の型

type Features struct

フィールド説明
PlanToolboolplan_create 関連の runtime 補助ツールを登録するか。
Guardboolruntime 内で guard を有効にするか。
Skillsboolprompt 構築時に skills 読み込みを有効にするか。

type InspectOptions struct

フィールド説明
Promptboolprompt をファイル出力するか。
Requestboolrequest / response をファイル出力するか。
DumpDirstring出力先ディレクトリ。
Modestring出力を区別する inspect モード名。
TimestampFormatstringファイル名に使う時刻フォーマット。

type Config struct

フィールド説明
Overridesmap[string]any最終 override を viper key で保持する map。優先度は最上位。
Featuresintegration.Featuresどの runtime 機能を接続するかを制御。
PromptBlocks[]stringsystem prompt の Additional Policies に追加される静的 block。
BuiltinToolNames[]string組み込みツールの allowlist。空なら全て有効。
Inspectintegration.InspectOptionsprompt / request 出力関連のデバッグ設定。

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

項目内容
引数key string:viper の設定キー。value any:上書き値
戻り値なし
説明Overrides に単一の override を書き込みます。空 key は無視されます。

(*Config).AddPromptBlock(content string)

項目内容
引数content string:追加する prompt block
戻り値なし
説明静的 prompt block を 1 つ追加します。空白文字だけの文字列は無視され、内容は順番通り runtime に適用されます。

Runtime と実行

type Runtime struct

Runtime はサードパーティ埋め込みの主入口です。フィールドは公開せず、主にメソッド経由で使います。

type PreparedRun struct

フィールド説明
Engine*agent.Engine実行準備済みの engine。
Modelstring現在のメイン route から解決された model 名。
Cleanupfunc() errorinspect 出力や MCP 接続などの一時リソースを解放する関数。

type LLMProfile struct

フィールド説明
Namestringprofile 名。
Providerstring解決後の provider 名。
ModelNamestring解決後の model 名。
APIBasestring存在する場合の API base。

type LLMProfileCandidate struct

フィールド説明
LLMProfileintegration.LLMProfile候補 profile の情報。
Weightintllm.routes.main_loop.candidates に設定された重み。

type LLMProfileSelection struct

フィールド説明
Modestringauto または manual
ManualProfilestringModemanual のときの上書き対象 profile。
RouteTypestringprofile または candidates
Current*integration.LLMProfile単一 profile 戦略のときの現在 profile。
Candidates[]integration.LLMProfileCandidatecandidates 戦略のときの重み付き候補一覧。
FallbackProfiles[]integration.LLMProfileroute から解決された fallback profiles。

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

項目内容
引数なし
戻り値*tools.Registry
説明現在の runtime スナップショットからデフォルト registry を構築します。カスタムツールを足す場合は通常ここから始めます。

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

項目内容
引数ctx context.Context:準備フェーズの context。task string:現在の task テキスト
戻り値*integration.PreparedRunerror
説明デフォルト registry で再利用可能な engine を準備します。

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

項目内容
引数ctx context.Context:準備フェーズの context。task string:現在の task テキスト。baseReg *tools.Registry:基底 registry
戻り値*integration.PreparedRunerror
説明渡した registry を基底に engine を準備します。組み込みツールを残したままカスタムツールを足したい場合は、先に rt.NewRegistry() を呼んでから追加登録するのが普通です。

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

項目内容
引数ctx context.Context:実行 context。task string:task テキスト。opts agent.RunOptions:今回の実行オプション
戻り値*agent.Final*agent.Contexterror
説明一回限りの便利 API です。内部で一時的に engine を準備し、実行後に自動で Cleanup() します。

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

項目内容
引数なし
戻り値integration.LLMProfileSelectionerror
説明この runtime インスタンスにおける現在の main_loop selection を返します。candidates 戦略では単一 profile を返すのではなく、重み付き戦略そのものを返します。

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

項目内容
引数なし
戻り値[]integration.LLMProfileerror
説明設定済みの LLM profiles を一覧で返します。各要素には nameprovidermodel_name、必要に応じて api_base が含まれます。

(*Runtime).SetLLMProfile(profileName string) error

項目内容
引数profileName stringmain_loop に強制適用する profile 名
戻り値error
説明この runtime インスタンスを manual モードに切り替え、main_loop だけを上書きします。plan_create など他の purpose はそのままです。

(*Runtime).ResetLLMProfile()

項目内容
引数なし
戻り値なし
説明この runtime インスタンスの main_loop 手動 override を解除し、設定済みの route policy に戻します。

(*Runtime).RequestTimeout() time.Duration

項目内容
引数なし
戻り値time.Duration
説明現在の runtime スナップショットから解決された LLM request timeout を返します。

Channel Runner

type BotRunner interface

メソッド引数戻り値説明
Runctx context.Contexterror長寿命の channel bot を起動する。
Closeなしerrorrunner を能動的に閉じる。

type TelegramOptions struct

フィールド説明
BotTokenstringTelegram bot token。
AllowedChatIDs[]int64許可する chat の allowlist。
PollTimeouttime.DurationTelegram polling timeout。
TaskTimeouttime.Duration1 task あたりの実行 timeout。
MaxConcurrencyint最大同時実行数。
GroupTriggerModestringグループ trigger mode。
AddressingConfidenceThresholdfloat64addressing 判定の閾値。
AddressingInterjectThresholdfloat64interject 判定の閾値。
Hooksintegration.TelegramHooksイベント callback。

type SlackOptions struct

フィールド説明
BotTokenstringSlack bot token。
AppTokenstringSlack app token。
AllowedTeamIDs[]string許可する team の allowlist。
AllowedChannelIDs[]string許可する channel の allowlist。
TaskTimeouttime.Duration1 task あたりの実行 timeout。
MaxConcurrencyint最大同時実行数。
GroupTriggerModestringグループ trigger mode。
AddressingConfidenceThresholdfloat64addressing 判定の閾値。
AddressingInterjectThresholdfloat64interject 判定の閾値。
Hooksintegration.SlackHooksイベント callback。

type TelegramHooks struct

フィールド説明
OnInboundfunc(TelegramInboundEvent)入站イベント受信時に呼ばれる。
OnOutboundfunc(TelegramOutboundEvent)出站イベント送信時に呼ばれる。
OnErrorfunc(TelegramErrorEvent)runtime エラーイベント callback。

type SlackHooks struct

フィールド説明
OnInboundfunc(SlackInboundEvent)入站イベント受信時に呼ばれる。
OnOutboundfunc(SlackOutboundEvent)出站イベント送信時に呼ばれる。
OnErrorfunc(SlackErrorEvent)runtime エラーイベント callback。

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

項目内容
引数opts integration.TelegramOptions
戻り値integration.BotRunnererror
説明Telegram runner を構築します。BotToken が空なら即座に error を返します。

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

項目内容
引数opts integration.SlackOptions
戻り値integration.BotRunnererror
説明Slack runner を構築します。BotToken または AppToken が空なら即座に error を返します。

イベント alias 型

これらの公開 alias 型は主に hook の関数シグネチャで使います。

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

業務ロジック側では、通常は Hooks の中でこれらを受け取れば十分で、下位 runtime を直接触る必要はありません。