fix: put full JSON result in ForLLM, summary in ForUser
Accept suggestion from afjcjsbx: the LLM should receive the full JSON result (including extracted text) while the user sees a short summary. Update tests to match the new field assignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6edacb4f7e
commit
04e3130607
2 changed files with 25 additions and 19 deletions
|
|
@ -652,8 +652,14 @@ func (t *WebFetchTool) Execute(ctx context.Context, args map[string]any) *ToolRe
|
||||||
resultJSON, _ := json.MarshalIndent(result, "", " ")
|
resultJSON, _ := json.MarshalIndent(result, "", " ")
|
||||||
|
|
||||||
return &ToolResult{
|
return &ToolResult{
|
||||||
ForLLM: text,
|
ForLLM: string(resultJSON),
|
||||||
ForUser: string(resultJSON),
|
ForUser: fmt.Sprintf(
|
||||||
|
"Fetched %d bytes from %s (extractor: %s, truncated: %v)",
|
||||||
|
len(text),
|
||||||
|
urlStr,
|
||||||
|
extractor,
|
||||||
|
truncated,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,14 +32,14 @@ func TestWebTool_WebFetch_Success(t *testing.T) {
|
||||||
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForUser should contain the fetched content
|
// ForLLM should contain the fetched content (full JSON result)
|
||||||
if !strings.Contains(result.ForUser, "Test Page") {
|
if !strings.Contains(result.ForLLM, "Test Page") {
|
||||||
t.Errorf("Expected ForUser to contain 'Test Page', got: %s", result.ForUser)
|
t.Errorf("Expected ForLLM to contain 'Test Page', got: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForLLM should contain summary
|
// ForUser should contain summary
|
||||||
if !strings.Contains(result.ForLLM, "bytes") && !strings.Contains(result.ForLLM, "extractor") {
|
if !strings.Contains(result.ForUser, "bytes") && !strings.Contains(result.ForUser, "extractor") {
|
||||||
t.Errorf("Expected ForLLM to contain summary, got: %s", result.ForLLM)
|
t.Errorf("Expected ForUser to contain summary, got: %s", result.ForUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,9 +68,9 @@ func TestWebTool_WebFetch_JSON(t *testing.T) {
|
||||||
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForUser should contain formatted JSON
|
// ForLLM should contain formatted JSON
|
||||||
if !strings.Contains(result.ForUser, "key") && !strings.Contains(result.ForUser, "value") {
|
if !strings.Contains(result.ForLLM, "key") && !strings.Contains(result.ForLLM, "value") {
|
||||||
t.Errorf("Expected ForUser to contain JSON data, got: %s", result.ForUser)
|
t.Errorf("Expected ForLLM to contain JSON data, got: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,9 +159,9 @@ func TestWebTool_WebFetch_Truncation(t *testing.T) {
|
||||||
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForUser should contain truncated content (not the full 20000 chars)
|
// ForLLM should contain truncated content (not the full 20000 chars)
|
||||||
resultMap := make(map[string]any)
|
resultMap := make(map[string]any)
|
||||||
json.Unmarshal([]byte(result.ForUser), &resultMap)
|
json.Unmarshal([]byte(result.ForLLM), &resultMap)
|
||||||
if text, ok := resultMap["text"].(string); ok {
|
if text, ok := resultMap["text"].(string); ok {
|
||||||
if len(text) > 1100 { // Allow some margin
|
if len(text) > 1100 { // Allow some margin
|
||||||
t.Errorf("Expected content to be truncated to ~1000 chars, got: %d", len(text))
|
t.Errorf("Expected content to be truncated to ~1000 chars, got: %d", len(text))
|
||||||
|
|
@ -228,14 +228,14 @@ func TestWebTool_WebFetch_HTMLExtraction(t *testing.T) {
|
||||||
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
t.Errorf("Expected success, got IsError=true: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForUser should contain extracted text (without script/style tags)
|
// ForLLM should contain extracted text (without script/style tags)
|
||||||
if !strings.Contains(result.ForUser, "Title") && !strings.Contains(result.ForUser, "Content") {
|
if !strings.Contains(result.ForLLM, "Title") && !strings.Contains(result.ForLLM, "Content") {
|
||||||
t.Errorf("Expected ForUser to contain extracted text, got: %s", result.ForUser)
|
t.Errorf("Expected ForLLM to contain extracted text, got: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should NOT contain script or style tags
|
// Should NOT contain script or style tags in ForLLM
|
||||||
if strings.Contains(result.ForUser, "<script>") || strings.Contains(result.ForUser, "<style>") {
|
if strings.Contains(result.ForLLM, "<script>") || strings.Contains(result.ForLLM, "<style>") {
|
||||||
t.Errorf("Expected script/style tags to be removed, got: %s", result.ForUser)
|
t.Errorf("Expected script/style tags to be removed, got: %s", result.ForLLM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue