You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(llm tools): Add patternTool helper to support pattern LLM tools (#1962)
* feat: Add extraParams support to LLM tool definitions
Adds the ability to pass extra parameters to pattern-based tools in LLM
dialog tool invocations. This allows tool definitions to specify additional
static parameters that get merged with the LLM-provided input when invoking
the underlying pattern.
Changes:
- Add extraParams field to LLMToolSchema for pattern-based tools
- Merge extraParams with tool call input when invoking patterns
- Update calculator pattern to accept optional base parameter
- Add example usage in default-app with base: 10 for calculator tool
This enables use cases like configuring tool behavior (e.g., number base
for calculator) without requiring the LLM to provide those values.
* feat: Allow patterns as LLM tool actions via OpaqueRef
Extends LLM tool system to support passing pattern recipes as actions,
not just handler streams. This enables using recipes with extraParams
directly as tool definitions.
Changes:
- Modified invokeToolCall to accept pattern and extraParams via charmMeta
- Updated tool resolution in startRequest to detect and extract patterns
from OpaqueRef cells
- Added grep pattern example in note.tsx demonstrating the new capability
This allows more flexible tool definitions where patterns can be
composed with additional parameters and used as LLM actions.
* feat: Add patternTool helper for LLM tool definitions with pre-filled params
Add a new `patternTool` helper function that simplifies creating LLM tool
definitions from recipes with optional pre-filled parameters. This eliminates
the need for manual type casting and provides automatic type inference.
The helper:
- Automatically creates a recipe with description "tool"
- Constructs the { pattern, extraParams } object structure
- Properly types the result as OpaqueRef<Omit<T, keyof E>> (excluding pre-filled params)
- No manual type casting needed
Example usage:
```typescript
grep: patternTool(
({ query, content }: { query: string; content: string }) => {
return derive({ query, content }, ({ query, content }) => {
return content.split("\n").filter((c) => c.includes(query));
});
},
{ content },
),
// Type is automatically inferred as OpaqueRef<{ query: string }>
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* compile api types
* feat: Allow patternTool to accept existing recipes
Extend patternTool to accept either a function or an already-created
RecipeFactory. This provides flexibility when you want to reuse an existing
recipe with pre-filled parameters.
The function now:
- Checks if the input is a recipe using isRecipe()
- Only creates a new recipe if a function is passed
- Reuses the existing recipe if a RecipeFactory is passed
Example usage with existing recipe:
```typescript
const myRecipe = recipe<{ query: string; content: string }>(
"Grep",
({ query, content }) => { ... }
);
// Pass existing recipe with extra params
const tool = patternTool(myRecipe, { content });
// Type: OpaqueRef<{ query: string }>
```
Updated default-app.tsx to demonstrate this pattern with the calculator tool.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* sanitize base input
* patternTool's 2nd parameter is optional, adjust type accordingly
---------
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments