Skip to repository content79 lines · 2.5 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:36:29.070Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
list_agents_and_models_tool.rs
1use agent_client_protocol::schema::v1 as acp;
2use anyhow::Result;
3use gpui::{App, SharedString, Task};
4use language_model::LanguageModelToolResultContent;
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use std::rc::Rc;
8use std::sync::Arc;
9
10use crate::{AgentTool, AvailableAgents, ThreadEnvironment, ToolCallEventStream, ToolInput};
11
12/// List the agents and models available for use with the `create_thread` tool.
13///
14/// Call this before `create_thread` if you need to pick a specific agent or a
15/// non-default model (for example, to use a cheaper model for bulk work). If
16/// you're happy with the user's current defaults, you don't need to call this.
17#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
18#[serde(rename_all = "snake_case")]
19pub struct ListAgentsAndModelsToolInput {}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
22#[serde(untagged)]
23pub enum ListAgentsAndModelsToolOutput {
24 Success(AvailableAgents),
25 Error { error: String },
26}
27
28impl From<ListAgentsAndModelsToolOutput> for LanguageModelToolResultContent {
29 fn from(output: ListAgentsAndModelsToolOutput) -> Self {
30 serde_json::to_string(&output)
31 .unwrap_or_else(|e| format!("Failed to serialize list_agents_and_models output: {e}"))
32 .into()
33 }
34}
35
36pub struct ListAgentsAndModelsTool {
37 environment: Rc<dyn ThreadEnvironment>,
38}
39
40impl ListAgentsAndModelsTool {
41 pub fn new(environment: Rc<dyn ThreadEnvironment>) -> Self {
42 Self { environment }
43 }
44}
45
46impl AgentTool for ListAgentsAndModelsTool {
47 type Input = ListAgentsAndModelsToolInput;
48 type Output = ListAgentsAndModelsToolOutput;
49
50 const NAME: &'static str = "list_agents_and_models";
51
52 fn kind() -> acp::ToolKind {
53 acp::ToolKind::Other
54 }
55
56 fn initial_title(
57 &self,
58 _input: Result<Self::Input, serde_json::Value>,
59 _cx: &mut App,
60 ) -> SharedString {
61 "List agents and models".into()
62 }
63
64 fn run(
65 self: Arc<Self>,
66 _input: ToolInput<Self::Input>,
67 _event_stream: ToolCallEventStream,
68 cx: &mut App,
69 ) -> Task<Result<Self::Output, Self::Output>> {
70 let result = self.environment.list_available_agents(cx);
71 Task::ready(match result {
72 Ok(agents) => Ok(ListAgentsAndModelsToolOutput::Success(agents)),
73 Err(error) => Err(ListAgentsAndModelsToolOutput::Error {
74 error: error.to_string(),
75 }),
76 })
77 }
78}
79