Skip to content

Commit 85e27ec

Browse files
authored
feat: add agent options to model config (#6383)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 698205a commit 85e27ec

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

core/config/model_config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,22 @@ type ModelConfig struct {
7474
Options []string `yaml:"options" json:"options"`
7575
Overrides []string `yaml:"overrides" json:"overrides"`
7676

77-
MCP MCPConfig `yaml:"mcp" json:"mcp"`
77+
MCP MCPConfig `yaml:"mcp" json:"mcp"`
78+
Agent AgentConfig `yaml:"agent" json:"agent"`
7879
}
7980

8081
type MCPConfig struct {
8182
Servers string `yaml:"remote" json:"remote"`
8283
Stdio string `yaml:"stdio" json:"stdio"`
8384
}
8485

86+
type AgentConfig struct {
87+
MaxAttempts int `yaml:"max_attempts" json:"max_attempts"`
88+
MaxIterations int `yaml:"max_iterations" json:"max_iterations"`
89+
EnableReasoning bool `yaml:"enable_reasoning" json:"enable_reasoning"`
90+
EnableReEvaluation bool `yaml:"enable_re_evaluation" json:"enable_re_evaluation"`
91+
}
92+
8593
func (c *MCPConfig) MCPConfigFromYAML() (MCPGenericConfig[MCPRemoteServers], MCPGenericConfig[MCPSTDIOServers]) {
8694
var remote MCPGenericConfig[MCPRemoteServers]
8795
var stdio MCPGenericConfig[MCPSTDIOServers]

core/http/endpoints/openai/mcp.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,35 @@ func MCPCompletionEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader,
9595
// we satisfy to just call internally ComputeChoices
9696
defaultLLM := cogito.NewOpenAILLM(config.Name, apiKey, "http://127.0.0.1:"+port)
9797

98-
f, err := cogito.ExecuteTools(
99-
defaultLLM, fragment,
98+
cogitoOpts := []cogito.Option{
10099
cogito.WithStatusCallback(func(s string) {
101100
log.Debug().Msgf("[model agent] [model: %s] Status: %s", config.Name, s)
102101
}),
103102
cogito.WithContext(ctx),
104-
// TODO: move these to configs
105-
cogito.EnableToolReEvaluator,
106-
cogito.WithIterations(3),
107-
cogito.WithMaxAttempts(3),
108-
cogito.WithTools(
109-
cogitoTools...,
110-
),
103+
cogito.WithTools(cogitoTools...),
104+
cogito.WithIterations(3), // default to 3 iterations
105+
cogito.WithMaxAttempts(3), // default to 3 attempts
106+
}
107+
108+
if config.Agent.EnableReasoning {
109+
cogitoOpts = append(cogitoOpts, cogito.EnableToolReasoner)
110+
}
111+
112+
if config.Agent.EnableReEvaluation {
113+
cogitoOpts = append(cogitoOpts, cogito.EnableToolReEvaluator)
114+
}
115+
116+
if config.Agent.MaxIterations != 0 {
117+
cogitoOpts = append(cogitoOpts, cogito.WithIterations(config.Agent.MaxIterations))
118+
}
119+
120+
if config.Agent.MaxAttempts != 0 {
121+
cogitoOpts = append(cogitoOpts, cogito.WithMaxAttempts(config.Agent.MaxAttempts))
122+
}
123+
124+
f, err := cogito.ExecuteTools(
125+
defaultLLM, fragment,
126+
cogitoOpts...,
111127
)
112128
if err != nil && !errors.Is(err, cogito.ErrNoToolSelected) {
113129
return err

docs/content/docs/features/mcp.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ The Model Context Protocol is a standard for connecting AI models to external to
2727
- **⚡ Cached Connections**: Efficient tool caching for better performance
2828
- **🔒 Secure Authentication**: Support for bearer token authentication
2929
- **🎯 OpenAI Compatible**: Uses the familiar `/mcp/v1/chat/completions` endpoint
30+
- **🧠 Advanced Reasoning**: Configurable reasoning and re-evaluation capabilities
31+
- **⚙️ Flexible Agent Control**: Customizable execution limits and retry behavior
3032

3133
## Configuration
3234

@@ -73,6 +75,13 @@ mcp:
7375
}
7476
}
7577
}
78+
79+
# Agent Configuration
80+
agent:
81+
max_attempts: 3 # Maximum number of tool execution attempts
82+
max_iterations: 3 # Maximum number of reasoning iterations
83+
enable_reasoning: true # Enable tool reasoning capabilities
84+
enable_re_evaluation: false # Enable tool re-evaluation
7685
```
7786
7887
### Configuration Options
@@ -90,6 +99,14 @@ Configure local command-based MCP servers:
9099
- **`args`**: Array of command-line arguments
91100
- **`env`**: Environment variables (optional)
92101

102+
#### Agent Configuration (`agent`)
103+
Configure agent behavior and tool execution:
104+
105+
- **`max_attempts`**: Maximum number of tool execution attempts (default: 3)
106+
- **`max_iterations`**: Maximum number of reasoning iterations (default: 3)
107+
- **`enable_reasoning`**: Enable tool reasoning capabilities (default: false)
108+
- **`enable_re_evaluation`**: Enable tool re-evaluation (default: false)
109+
93110
## Usage
94111

95112
### API Endpoint
@@ -148,8 +165,31 @@ mcp:
148165
}
149166
}
150167
}
168+
169+
agent:
170+
max_attempts: 5
171+
max_iterations: 5
172+
enable_reasoning: true
173+
enable_re_evaluation: true
151174
```
152175

176+
## Agent Configuration Details
177+
178+
The `agent` section controls how the AI model interacts with MCP tools:
179+
180+
### Execution Control
181+
- **`max_attempts`**: Limits how many times a tool can be retried if it fails. Higher values provide more resilience but may increase response time.
182+
- **`max_iterations`**: Controls the maximum number of reasoning cycles the agent can perform. More iterations allow for complex multi-step problem solving.
183+
184+
### Reasoning Capabilities
185+
- **`enable_reasoning`**: When enabled, the agent uses advanced reasoning to better understand tool results and plan next steps.
186+
- **`enable_re_evaluation`**: When enabled, the agent can re-evaluate previous tool results and decisions, allowing for self-correction and improved accuracy.
187+
188+
### Recommended Settings
189+
- **Simple tasks**: `max_attempts: 2`, `max_iterations: 2`, `enable_reasoning: false`
190+
- **Complex tasks**: `max_attempts: 5`, `max_iterations: 5`, `enable_reasoning: true`, `enable_re_evaluation: true`
191+
- **Development/Debugging**: `max_attempts: 1`, `max_iterations: 1`, `enable_reasoning: true`, `enable_re_evaluation: true`
192+
153193
## How It Works
154194

155195
1. **Tool Discovery**: LocalAI connects to configured MCP servers and discovers available tools

0 commit comments

Comments
 (0)