mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
* perf: build system prompt once per turn, skip tools on force-text, fix nudge role (#565) Three fixes to agentic loop prompt handling: 1. Build system prompt once per turn instead of every tool iteration. `build_system_prompt_with_tools` is now pub; callers pass the result via `ReasoningContext::system_prompt` to avoid rebuilding ~1,500 tokens per iteration. 2. Skip `## Available Tools` section when `force_text = true`. The dispatcher passes a no-tools prompt variant on the final iteration, saving ~460 tokens and removing misleading instructions. 3. Change nudge message from `Role::System` to `Role::User`. A second system message mid-conversation is unsupported by most providers. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: revert nudge role change to keep ChatMessage::system Copilot review correctly identified that using Role::User for the nudge breaks compact_messages_for_retry, which uses rposition for Role::User to find the last real user message. Role::Assistant would cause back-to-back assistant messages. Since no production issues were reported with the original system role, revert to ChatMessage::system. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: address PR review — omit tool guidance when tools empty, rename shadowed var - Conditionalize "Call tools…" guidelines and "## Tool Call Style" section in the system prompt so they are only included when tools are non-empty. Previously the force-text (no-tools) prompt still contained misleading tool-calling instructions. (Copilot review comment) - Rename `system_prompt` → `cached_prompt` in dispatcher to avoid shadowing the earlier workspace identity `system_prompt` variable. (Copilot review) - Add regression tests: `test_system_prompt_with_tools_contains_tool_guidance` and extended assertions in `test_system_prompt_without_tools_omits_tools_section`. Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: [email protected] <[email protected]>
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
//! E2E trace test: validates that the agent can execute `write_file` and
|
|
//! `read_file` tool calls driven by a TraceLlm trace.
|
|
|
|
#[cfg(feature = "libsql")]
|
|
mod support;
|
|
|
|
#[cfg(feature = "libsql")]
|
|
mod tests {
|
|
use std::time::Duration;
|
|
|
|
use crate::support::cleanup::CleanupGuard;
|
|
use crate::support::test_rig::TestRigBuilder;
|
|
use crate::support::trace_llm::LlmTrace;
|
|
|
|
const TEST_DIR: &str = "/tmp/ironclaw_e2e_test";
|
|
const TEST_FILE: &str = "/tmp/ironclaw_e2e_test/hello.txt";
|
|
const EXPECTED_CONTENT: &str = "Hello, E2E test!";
|
|
|
|
fn setup_test_dir() {
|
|
let _ = std::fs::remove_dir_all(TEST_DIR);
|
|
std::fs::create_dir_all(TEST_DIR).expect("failed to create test directory");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_file_write_and_read_flow() {
|
|
setup_test_dir();
|
|
let _cleanup = CleanupGuard::new().dir(TEST_DIR);
|
|
|
|
let fixture_path = concat!(
|
|
env!("CARGO_MANIFEST_DIR"),
|
|
"/tests/fixtures/llm_traces/file_write_read.json"
|
|
);
|
|
let trace = LlmTrace::from_file(fixture_path).expect("failed to load trace fixture");
|
|
|
|
let rig = TestRigBuilder::new()
|
|
.with_trace(trace.clone())
|
|
.build()
|
|
.await;
|
|
|
|
rig.send_message("Please write a greeting to a file and read it back.")
|
|
.await;
|
|
let responses = rig.wait_for_responses(1, Duration::from_secs(15)).await;
|
|
|
|
rig.verify_trace_expects(&trace, &responses);
|
|
|
|
// Extra: verify file on disk (can't express in expects).
|
|
let file_content =
|
|
std::fs::read_to_string(TEST_FILE).expect("hello.txt should exist after write_file");
|
|
assert_eq!(file_content, EXPECTED_CONTENT);
|
|
|
|
rig.shutdown();
|
|
}
|
|
}
|