Tool Outputの仕様簡素化
This commit is contained in:
@@ -10,7 +10,7 @@ use async_trait::async_trait;
|
||||
use llm_worker::Worker;
|
||||
use llm_worker::llm_client::event::{Event, ResponseStatus, StatusEvent};
|
||||
use llm_worker::interceptor::{Interceptor, PostToolAction, PreToolAction, ToolCallInfo, ToolResultInfo};
|
||||
use llm_worker::tool::{Tool, ToolDefinition, ToolError, ToolMeta};
|
||||
use llm_worker::tool::{Tool, ToolDefinition, ToolError, ToolMeta, ToolOutput};
|
||||
|
||||
mod common;
|
||||
use common::MockLlmClient;
|
||||
@@ -57,10 +57,10 @@ impl SlowTool {
|
||||
|
||||
#[async_trait]
|
||||
impl Tool for SlowTool {
|
||||
async fn execute(&self, _input_json: &str) -> Result<String, ToolError> {
|
||||
async fn execute(&self, _input_json: &str) -> Result<ToolOutput, ToolError> {
|
||||
self.call_count.fetch_add(1, Ordering::SeqCst);
|
||||
tokio::time::sleep(Duration::from_millis(self.delay_ms)).await;
|
||||
Ok(format!("Completed after {}ms", self.delay_ms))
|
||||
Ok(format!("Completed after {}ms", self.delay_ms).into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +218,8 @@ async fn test_post_tool_call_modification() {
|
||||
|
||||
#[async_trait]
|
||||
impl Tool for SimpleTool {
|
||||
async fn execute(&self, _: &str) -> Result<String, ToolError> {
|
||||
Ok("Original Result".to_string())
|
||||
async fn execute(&self, _: &str) -> Result<ToolOutput, ToolError> {
|
||||
Ok("Original Result".to_string().into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,8 +242,8 @@ async fn test_post_tool_call_modification() {
|
||||
#[async_trait]
|
||||
impl Interceptor for ModifyingPolicy {
|
||||
async fn post_tool_call(&self, info: &mut ToolResultInfo) -> PostToolAction {
|
||||
info.result.content = format!("[Modified] {}", info.result.content);
|
||||
*self.modified_content.lock().unwrap() = Some(info.result.content.clone());
|
||||
info.result.summary = format!("[Modified] {}", info.result.summary);
|
||||
*self.modified_content.lock().unwrap() = Some(info.result.summary.clone());
|
||||
PostToolAction::Continue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ async fn test_basic_tool_generation() {
|
||||
let result = tool.execute(r#"{"message": "World"}"#).await;
|
||||
assert!(result.is_ok(), "Should execute successfully");
|
||||
let output = result.unwrap();
|
||||
assert!(output.contains("Hello"), "Output should contain prefix");
|
||||
assert!(output.contains("World"), "Output should contain message");
|
||||
assert!(output.summary.contains("Hello"), "Output should contain prefix");
|
||||
assert!(output.summary.contains("World"), "Output should contain message");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -94,7 +94,7 @@ async fn test_multiple_arguments() {
|
||||
let result = tool.execute(r#"{"a": 10, "b": 20}"#).await;
|
||||
assert!(result.is_ok());
|
||||
let output = result.unwrap();
|
||||
assert!(output.contains("30"), "Should contain sum: {}", output);
|
||||
assert!(output.summary.contains("30"), "Should contain sum: {:?}", output);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -112,8 +112,8 @@ async fn test_no_arguments() {
|
||||
assert!(result.is_ok());
|
||||
let output = result.unwrap();
|
||||
assert!(
|
||||
output.contains("TestPrefix"),
|
||||
"Should contain prefix: {}",
|
||||
output.summary.contains("TestPrefix"),
|
||||
"Should contain prefix: {:?}",
|
||||
output
|
||||
);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ async fn test_result_return_type_success() {
|
||||
let result = tool.execute(r#"{"value": 42}"#).await;
|
||||
assert!(result.is_ok(), "Should succeed for positive value");
|
||||
let output = result.unwrap();
|
||||
assert!(output.contains("Valid"), "Should contain Valid: {}", output);
|
||||
assert!(output.summary.contains("Valid"), "Should contain Valid: {:?}", output);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use async_trait::async_trait;
|
||||
use common::MockLlmClient;
|
||||
use llm_worker::Worker;
|
||||
use llm_worker::tool::{Tool, ToolDefinition, ToolError, ToolMeta};
|
||||
use llm_worker::tool::{Tool, ToolDefinition, ToolError, ToolMeta, ToolOutput};
|
||||
|
||||
/// Fixture directory path
|
||||
fn fixtures_dir() -> std::path::PathBuf {
|
||||
@@ -58,7 +58,7 @@ impl MockWeatherTool {
|
||||
|
||||
#[async_trait]
|
||||
impl Tool for MockWeatherTool {
|
||||
async fn execute(&self, input_json: &str) -> Result<String, ToolError> {
|
||||
async fn execute(&self, input_json: &str) -> Result<ToolOutput, ToolError> {
|
||||
self.call_count.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
// Parse input
|
||||
@@ -68,7 +68,7 @@ impl Tool for MockWeatherTool {
|
||||
let city = input["city"].as_str().unwrap_or("Unknown");
|
||||
|
||||
// Return mock response
|
||||
Ok(format!("Weather in {}: Sunny, 22°C", city))
|
||||
Ok(format!("Weather in {}: Sunny, 22°C", city).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use common::MockLlmClient;
|
||||
use llm_worker::Item;
|
||||
use llm_worker::{Worker, WorkerError};
|
||||
use llm_worker::llm_client::event::{Event, ResponseStatus, StatusEvent};
|
||||
use llm_worker::tool::{Tool, ToolDefinition, ToolError, ToolMeta};
|
||||
use llm_worker::tool::{Tool, ToolDefinition, ToolError, ToolMeta, ToolOutput};
|
||||
|
||||
// =============================================================================
|
||||
// Mutable State Tests
|
||||
@@ -134,9 +134,9 @@ impl CountingTool {
|
||||
|
||||
#[async_trait]
|
||||
impl Tool for CountingTool {
|
||||
async fn execute(&self, _input_json: &str) -> Result<String, ToolError> {
|
||||
async fn execute(&self, _input_json: &str) -> Result<ToolOutput, ToolError> {
|
||||
self.calls.fetch_add(1, Ordering::SeqCst);
|
||||
Ok(format!("{}-ok", self.name))
|
||||
Ok(format!("{}-ok", self.name).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user