Skip to content

Commit 6ec5d34

Browse files
authored
Custom tool block syntax (new triple-caret syntax implementation) (#41)
Also includes better session activity tracking / visualization, and saving draft messages per session.
1 parent d7468b3 commit 6ec5d34

30 files changed

+4839
-849
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Available options:
105105
- `-p, --provider <PROVIDER>`: LLM provider to use [ai-core, anthropic, open-ai, ollama, vertex, open-router] (default: anthropic)
106106
- `-m, --model <MODEL>`: Model name to use (provider-specific defaults: anthropic="claude-sonnet-4-20250514", open-ai="gpt-4o", vertex="gemini-2.5-pro-preview-06-05", open-router="anthropic/claude-3-7-sonnet", ollama=required)
107107
- `--base-url <BASE_URL>`: API base URL for the LLM provider to use
108-
- `--tools-type <TOOLS_TYPE>`: Type of tool declaration [native, xml] (default: xml) - `native` = tools via API, `xml` = custom system message
108+
- `--tool-syntax <TOOL_SYNTAX>`: Tool invocation syntax [native, xml, caret] (default: xml) - `native` = tools via API, `xml` = custom system message with XML tags, `caret` = custom system message with triple-caret blocks
109109
- `--num-ctx <NUM_CTX>`: Context window size in tokens (default: 8192, only relevant for Ollama)
110110
- `--record <RECORD>`: Record API responses to a file (only supported for Anthropic provider currently)
111111
- `--playback <PLAYBACK>`: Play back a recorded session from a file
@@ -162,6 +162,9 @@ Available options:
162162
This section is not really a roadmap, as the items are in no particular order.
163163
Below are some topics that are likely the next focus.
164164

165+
- **Block Replacing in Changed Files**: When streaming a tool use block, we already know the LLM attempts to use `replace_in_file` and we know in which file quite early.
166+
If we also know this file has changed since the LLM last read it, we can block the attempt with an appropriate error message.
167+
- **Compact Tool Use Failures**: When the LLM produces an invalid tool call, or a mismatching search block, we should be able to strip the failed attempt from the message history, saving tokens.
165168
- **Improve UI**: There are various ways in which the UI can be improved.
166169
- **Add Memory Tools**: Add tools that facilitate building up a knowledge base useful work working in a given project.
167170
- **Security**: Ideally, the execution for all tools would run in some sort of sandbox that restricts access to the files in the project tracked by git.

crates/code_assistant/resources/system_message_tools.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,7 @@ TOOL USE
2020

2121
You have access to a set of tools. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
2222

23-
# Tool Use Formatting
24-
25-
Tool use is formatted using XML-style tags. The tool name is prefixed by 'tool:' and enclosed in opening and closing tags, and each parameter is similarly prefixed with 'param:' and enclosed within its own set of tags. Here's the structure:
26-
27-
<tool:tool_name>
28-
<param:parameter1_name>value1</param:parameter1_name>
29-
<param:parameter2_name>
30-
value can stretch
31-
multiple lines
32-
</param:parameter2_name>
33-
...
34-
</tool:tool_name>
35-
36-
For example:
37-
38-
<tool:read_files>
39-
<param:project>frontend</param:project>
40-
<param:path>src/main.js</param:path>
41-
</tool:read_files>
42-
43-
Always adhere to this format for the tool use to ensure proper parsing and execution.
23+
{{syntax}}
4424

4525
# Tools
4626

crates/code_assistant/src/agent/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ mod tests;
33

44
pub mod persistence;
55
pub mod runner;
6-
mod tool_description_generator;
76
mod types;
87

9-
pub use crate::types::ToolMode;
8+
pub use crate::types::ToolSyntax;
109
pub use persistence::FileStatePersistence;
1110
pub use runner::Agent;
1211
pub use types::ToolExecution;

crates/code_assistant/src/agent/persistence.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex};
66
use crate::agent::types::ToolExecution;
77
use crate::persistence::{ChatSession, SerializedToolExecution};
88
use crate::session::SessionManager;
9-
use crate::types::{ToolMode, WorkingMemory};
9+
use crate::types::{ToolSyntax, WorkingMemory};
1010

1111
use std::time::SystemTime;
1212
use tracing::{debug, info};
@@ -117,16 +117,16 @@ const STATE_FILE: &str = ".code-assistant.state.json";
117117
#[derive(Clone)]
118118
pub struct FileStatePersistence {
119119
state_file_path: PathBuf,
120-
tool_mode: ToolMode,
120+
tool_syntax: ToolSyntax,
121121
}
122122

123123
impl FileStatePersistence {
124-
pub fn new(working_dir: &Path, tool_mode: ToolMode) -> Self {
124+
pub fn new(working_dir: &Path, tool_syntax: ToolSyntax) -> Self {
125125
let state_file_path = working_dir.join(STATE_FILE);
126126
info!("Using state file: {}", state_file_path.display());
127127
Self {
128128
state_file_path,
129-
tool_mode,
129+
tool_syntax,
130130
}
131131
}
132132

@@ -189,7 +189,7 @@ impl AgentStatePersistence for FileStatePersistence {
189189
working_memory,
190190
init_path,
191191
initial_project,
192-
tool_mode: self.tool_mode,
192+
tool_syntax: self.tool_syntax,
193193
next_request_id,
194194
};
195195

0 commit comments

Comments
 (0)