3e99b37683
- Added base_url and model fields to HarnessConfig in json_types.hpp - Removed base_url and model from OllamaConfig in ollama_client.hpp - Updated OllamaClient constructor to accept base_url and model as separate parameters - Updated main.cpp to use HarnessConfig for base_url and model - Updated agent_tool.cpp to use new OllamaClient constructor - Added test_harness_config.sh to verify the new config fields - Updated README.md to document the config fields
71 lines
2.5 KiB
C++
71 lines
2.5 KiB
C++
#include "agent_tool.hpp"
|
|
#include "harness.hpp"
|
|
#include "ollama_client.hpp"
|
|
#include "json_types.hpp"
|
|
#include <iostream>
|
|
|
|
static size_t g_depth = 0;
|
|
|
|
struct DepthGuard {
|
|
DepthGuard() { ++g_depth; }
|
|
~DepthGuard() { --g_depth; }
|
|
};
|
|
|
|
struct AgentTaskParams {
|
|
std::string task;
|
|
};
|
|
DRH_DEFINE_TYPE_REQUIRED(AgentTaskParams, task)
|
|
|
|
Tool make_agent_tool(const AgentProfile& profile,
|
|
const ToolRegistry& registry,
|
|
const std::string& base_url) {
|
|
return Tool{
|
|
.name = "agent_" + profile.name,
|
|
.description = profile.description,
|
|
.parameters_schema = {
|
|
{"type", "object"},
|
|
{"properties", {
|
|
{"task", {
|
|
{"type", "string"},
|
|
{"description", "The task to assign to this agent."}
|
|
}}
|
|
}},
|
|
{"required", {"task"}}
|
|
},
|
|
.execute = create_tool_execute<AgentTaskParams>([profile, ®istry, base_url](const AgentTaskParams& params) -> std::string {
|
|
|
|
DepthGuard guard;
|
|
size_t depth = g_depth;
|
|
std::string prefix = std::string(depth, '>') + " ";
|
|
std::string task = params.task;
|
|
|
|
std::cerr << prefix << "[agent:" << profile.name << "] " << task << "\n";
|
|
|
|
auto sub_reg_result = registry.create_subregistry(profile.tool_names);
|
|
if (!sub_reg_result) {
|
|
std::cerr << prefix << "[agent error:" << profile.name << "] " << sub_reg_result.error() << "\n";
|
|
return std::string("Agent error: ") + sub_reg_result.error();
|
|
}
|
|
ToolRegistry sub_registry = std::move(sub_reg_result.value());
|
|
|
|
Harness harness(std::make_unique<OllamaClient>(base_url, profile.model, OllamaConfig{
|
|
.timeout_s = 120
|
|
}), sub_registry, HarnessConfig{
|
|
.max_tool_iterations = 16,
|
|
.verbose = true,
|
|
.depth = depth,
|
|
.base_url = base_url,
|
|
.model = profile.model
|
|
});
|
|
|
|
auto result = harness.chat(task);
|
|
if (!result) {
|
|
std::cerr << prefix << "[agent error:" << profile.name << "] " << result.error() << "\n";
|
|
return std::string("Agent error: ") + result.error();
|
|
}
|
|
std::cerr << prefix << "[agent done:" << profile.name << "]\n";
|
|
return result.value();
|
|
})
|
|
};
|
|
}
|