Skip to content

Commit 6683a60

Browse files
committed
feat: Add Anthropic provider, fix in tools
1 parent 40a92b2 commit 6683a60

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

huly-coder.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# You can override config in ~\huly-coder.yaml file
33
#
44

5+
### Example Anthropic config
6+
# provider: Anthropic
7+
# model: claude-3-5-sonnet-latest
8+
# provider_api_key: sk-xxxxxxxxxxxxxxxxxxxxx
9+
510
#provider: LMStudio
611
provider: OpenRouter
712
#model: qwen3-8b

src/agent/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ impl Agent {
248248
.build(),
249249
))
250250
}
251+
ProviderKind::Anthropic => {
252+
let agent_builder = rig::providers::anthropic::ClientBuilder::new(
253+
&config
254+
.provider_api_key
255+
.clone()
256+
.expect("provider_api_key is required for Anthropic"),
257+
)
258+
.build()
259+
.agent(&config.model);
260+
Ok(Box::new(
261+
Self::configure_agent(agent_builder, config, system_prompt, memory)
262+
.await?
263+
.build(),
264+
))
265+
}
251266
ProviderKind::OpenRouter => {
252267
let agent_builder = crate::providers::openrouter::Client::new(
253268
&config
@@ -431,11 +446,12 @@ impl Agent {
431446
}
432447
let mut result_message = Message::User {
433448
content: OneOrMany::one(UserContent::tool_result(
434-
tool_call.id,
449+
tool_call.id.clone(),
435450
OneOrMany::one(ToolResultContent::text(tool_result)),
436451
)),
437452
};
438453
if tool_call.function.name == AttemptCompletionTool::NAME {
454+
self.pending_tool_id = Some(tool_call.id.clone());
439455
self.set_state(AgentState::Completed(false));
440456
tracing::info!("Stop task with success");
441457
persist_history(&self.messages);

src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub enum ProviderKind {
1313
OpenAI,
1414
OpenRouter,
1515
LMStudio,
16+
Anthropic,
1617
}
1718

1819
#[derive(Debug, Deserialize, Clone)]

src/providers/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,24 @@ impl HulyAgent for Agent<rig::providers::openai::CompletionModel> {
6363
&self.tools
6464
}
6565
}
66+
67+
#[async_trait]
68+
impl HulyAgent for Agent<rig::providers::anthropic::completion::CompletionModel> {
69+
async fn send_messages(
70+
&self,
71+
prompt: Message,
72+
chat_history: Vec<Message>,
73+
) -> Result<
74+
StreamingCompletionResponse<rig::providers::openai::StreamingCompletionResponse>,
75+
CompletionError,
76+
> {
77+
self.stream_completion(prompt, chat_history)
78+
.await?
79+
.stream()
80+
.await
81+
}
82+
83+
fn tools(&self) -> &ToolSet {
84+
&self.tools
85+
}
86+
}

src/tools/execute_command.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ impl Tool for ExecuteCommandTool {
8585
.arg(args.command)
8686
.output()
8787
.map(|output| {
88-
serde_json::to_string(&format!(
88+
format!(
8989
"{}\n{}",
9090
String::from_utf8(output.stderr).unwrap_or_else(|_| "".to_string()),
9191
String::from_utf8(output.stdout).unwrap_or_else(|_| "".to_string())
92-
))
93-
.unwrap()
92+
)
9493
})?)
9594
}
9695
}

src/tools/read_file.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl Tool for ReadFileTool {
5959
async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
6060
let path = normalize_path(&self.workspace, &args.path);
6161
tracing::info!("Reading file {}", path);
62-
let content = fs::read_to_string(path)?;
63-
Ok(serde_json::to_string(&content)?)
62+
Ok(fs::read_to_string(path)?)
6463
}
6564
}

0 commit comments

Comments
 (0)