tycode_core/agents/agent.rs
1use std::sync::Arc;
2
3use crate::{
4 ai::types::Message,
5 module::{ContextComponentSelection, PromptComponentSelection},
6 tools::ToolName,
7};
8
9pub trait Agent: Send + Sync {
10 fn name(&self) -> &str;
11 fn description(&self) -> &str;
12 fn core_prompt(&self) -> &'static str;
13 fn available_tools(&self) -> Vec<ToolName>;
14
15 /// If there are prompt components installed, this instructs which
16 /// components should be included when building prompts for this agent.
17 ///
18 /// Prompt components are a way to define generic, reusable, slices of the
19 /// prompt which are reused by many agents, for example, how to talk to the
20 /// user, how to use your tools. Generally opting in to all prompt
21 /// components is a safe default, however some agents may wish to disable
22 /// or control prompt more.
23 fn requested_prompt_components(&self) -> PromptComponentSelection {
24 PromptComponentSelection::All
25 }
26
27 /// If there are context components, this instructs the `ContextBuilder` on
28 /// which components should be included when building contexts for this
29 /// agent.
30 ///
31 /// Context messages (aka "continuous steering") is a feature where the
32 /// last message to the agent always gives a big blob of up to date
33 /// context. For example, the context may have a list of files in the
34 /// project, some file contents, some memories, a task list, etc. All of
35 /// these are updated on each request to the AI to ensure the context is
36 /// always fresh. Stale versions of files, outdated task lists, etc never
37 /// appear in our agents context.
38 ///
39 /// Generally all context is helpful for agents, however if an agent needs
40 /// more fine grain control they may opt out of or control which context
41 /// components are included.
42 fn requested_context_components(&self) -> ContextComponentSelection {
43 ContextComponentSelection::All
44 }
45
46 fn requires_tool_use(&self) -> bool {
47 false
48 }
49}
50
51pub struct ActiveAgent {
52 pub agent: Arc<dyn Agent>,
53 pub conversation: Vec<Message>,
54 pub completion_result: Option<String>,
55}
56
57impl ActiveAgent {
58 pub fn new(agent: Arc<dyn Agent>) -> Self {
59 Self {
60 agent,
61 conversation: Vec::new(),
62 completion_result: None,
63 }
64 }
65}