feat: agents integration

This commit is contained in:
Gab
2026-03-27 08:52:47 +11:00
parent b9ced47bf8
commit 16bdb0707f
4 changed files with 125 additions and 67 deletions

View File

@@ -286,18 +286,18 @@ export namespace Agent {
return {
name: t.name,
description: t.description,
description: t.description ?? undefined,
mode: "primary" as const,
permission: Permission.fromConfig({ "*": "allow" }),
native: false,
prompt: t.interpolation_string,
goals: t.goals,
temperature: t.temperature,
prompt: t.interpolation_string ?? undefined,
goals: t.goals ?? undefined,
temperature: t.temperature ?? undefined,
model,
options: {
tf_agent_id: t.id,
tf_auth_via: t.auth_via,
tf_max_tokens: t.max_tokens,
tf_max_tokens: t.max_tokens ?? undefined,
},
}
})

View File

@@ -34,6 +34,12 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
}
}
const tfFallbackModel = createMemo(() => {
const m = { providerID: "toothfairyai", modelID: "mystica-15" }
if (isModelValid(m)) return m
return undefined
})
const agent = iife(() => {
const agents = createMemo(() => sync.data.agent.filter((x) => x.mode !== "subagent" && !x.hidden))
const visibleAgents = createMemo(() => sync.data.agent.filter((x) => !x.hidden))
@@ -192,10 +198,12 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
const currentModel = createMemo(() => {
const a = agent.current()
const isTFAgent = !!a.options?.tf_agent_id
return (
getFirstValidModel(
() => modelStore.model[a.name],
() => a.model,
() => (isTFAgent ? tfFallbackModel() : undefined),
fallbackModel,
) ?? undefined
)
@@ -297,6 +305,9 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
}
})
},
setDefault(model: { providerID: string; modelID: string }) {
setModelStore("model", agent.current().name, model)
},
toggleFavorite(model: { providerID: string; modelID: string }) {
batch(() => {
if (!isModelValid(model)) {
@@ -381,18 +392,23 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
// Automatically update model when agent changes
createEffect(() => {
const value = agent.current()
const isTFAgent = !!value.options?.tf_agent_id
if (value.model) {
if (isModelValid(value.model))
if (isModelValid(value.model)) {
model.set({
providerID: value.model.providerID,
modelID: value.model.modelID,
})
else
} else if (isTFAgent) {
// For TF agents with invalid model, force default to toothfairyai/mystica-15
model.setDefault({ providerID: "toothfairyai", modelID: "mystica-15" })
} else {
toast.show({
variant: "warning",
message: `Agent ${value.name}'s configured model ${value.model.providerID}/${value.model.modelID} is not valid`,
duration: 3000,
})
}
}
})

View File

@@ -116,11 +116,10 @@ export namespace LLM {
mergeDeep(variant),
)
// Remove TF-specific options for non-ToothFairyAI providers
if (input.model.providerID !== "toothfairyai") {
delete options.tf_agent_id
delete options.tf_auth_via
}
// Remove TF-specific internal tracking fields (never passed to APIs)
delete options.tf_agent_id
delete options.tf_auth_via
delete options.tf_max_tokens
if (isOpenaiOauth) {
options.instructions = system.join("\n")