Implementation:AI QL Tuui agentStore
| Knowledge Sources | |
|---|---|
| Domains | Agent_Config, Tool_Selection, State_Management |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for managing agent configurations including system prompts and scoped MCP tool subsets, provided by the tuui Electron application.
Description
The useAgentStore Pinia store manages named agents, each with a custom system prompt and a selected subset of MCP tools. getPrompt() returns the selected agent's system prompt. getTools() resolves the selected agent's tool nodes by parsing JSON-encoded { server, name } identifiers, listing tools from the specified servers via mcpStore.listServerTools, and filtering to only the selected tool names. If no agent is selected, all tools are returned via mcpStore.listTools(). State is persisted via pinia-plugin-persistedstate.
Usage
Import this store when you need to: get the system prompt for the current chat session, get the filtered tool set for the LLM request, or manage agent configurations.
Code Reference
Source Location
- Repository: tuui
- File: src/renderer/store/agent.ts
Signature
export const useAgentStore = defineStore('agentStore', {
state: (): AgentStoreState => ({
agents: AgentConfig[],
allTools: any[],
selected: number | null,
revised: number[]
}),
getters: {
hasTools(state): boolean
getRevised(state): AgentConfig | null
getUnrevised(state): AgentConfig[]
},
actions: {
getPrompt(): string
getTools(): Promise<FunctionType[]>
addAgent(): void
resetState(): void
genId(server: string, name: string): string
getId(id: string): { server: string, name: string }
getColor(id: string): string
getAbbr(input: string): string
}
})
export interface AgentConfig {
selectedNode: any[] // Array of JSON strings: '{"server":"srv","name":"tool"}'
name: string
prompt: string
}
Import
import { useAgentStore, type AgentConfig } from '@/renderer/store/agent'
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| selected | null | Yes (getPrompt/getTools) | Index into agents array; null = no agent |
| agents[selected].selectedNode | string[] | Yes (getTools) | JSON strings of { server, name } tool identifiers |
Outputs
| Name | Type | Description |
|---|---|---|
| getPrompt | string | System prompt for the selected agent ( if none selected) |
| getTools | FunctionType[] | Filtered tools in OpenAI format; all tools if no agent selected |
Usage Examples
Get Prompt and Tools for a Chat Request
import { useAgentStore } from '@/renderer/store/agent'
const agentStore = useAgentStore()
// Get the system prompt
const systemPrompt = agentStore.getPrompt()
// Get the filtered tool set
const tools = await agentStore.getTools()
// tools = [{ type: 'function', function: { name: 'read_file', description: '...', parameters: {...} } }]
Create a New Agent
const agentStore = useAgentStore()
agentStore.addAgent()
// New agent with default empty config and UUID name