Agent Tools
Understanding and working with AI agent tool functions for effective prompting
Please contact us at info@morphllm.com for access to the Morph Embeddings and Morph Reranking models.
Agent Tools for Code and File Manipulation
This guide explores the key tools available to AI agents for code and file manipulation, providing best practices for implementing and using these tools in your agent prompts.
Understanding Tool Architecture
Tools transform agents from conversational assistants to action-oriented systems. Effective agents require:
- Clear tool definitions: Functions with precise descriptions and parameters
- Usage protocols: Guidelines for when and how to use each tool
- Error handling: Procedures for when tools don’t behave as expected
The Edit File Tool
The edit_file
tool is the most critical tool for coding agents. It enables precise, fast modifications to any file in your codebase without requiring the reasoning agent to rewrite entire files.
How Edit File Works
The tool operates on a simple principle: show only what changes, mark everything else as unchanged. This approach:
- Minimizes token usage by not repeating large unchanged sections
- Reduces errors by providing clear context about what should change
- Enables precise edits in large files without full rewrites
- Works with any file type - code, configs, docs, anything
Key Concepts
- Precision: Only specify the lines that need to change
- Context Markers: Use
// ... existing code ...
to indicate unchanged sections - Clear Boundaries: Provide enough surrounding context for proper placement
Edit Format Examples
JavaScript/TypeScript files:
Python files:
Best Practices
- Read before you edit: Always examine the file first to understand its structure
- Minimal changes: Only include the lines that actually need modification
- Sufficient context: Include enough surrounding lines for unambiguous placement
- Language-appropriate comments: Use the correct comment syntax for each file type
- Clear instructions: Provide concise descriptions of what you’re changing
Common Patterns
Adding new code:
Modifying existing code:
Multiple changes in sequence:
Core File Manipulation Tools
Discovery and Navigation Tools
Advanced Tools
Tool Usage Workflow
Effective coding agents typically follow this tool usage pattern:
- Discovery: Use
list_dir
to understand project structure - Search: Use
codebase_search
orgrep_search
to find relevant code - Use Morph Embeddings and Morph Reranking to implement the tools - contact info@morphllm.com for access - Context Building: Use
read_file
to examine important sections - Modification: Use
edit_file
to make precise changes - Verification: Use
read_file
again to verify changes were applied correctly
Tool Prompting Guidelines
When implementing tools in your agent prompts:
- Clear function definitions: Provide comprehensive JSONSchema definitions
- Usage protocols: Define when and how each tool should be used
- Error handling: Include procedures for tool failures
- Context management: Guide the agent to build sufficient context before actions
- Progressive approach: Start with discovery, then focused understanding, then action
Common Tool Anti-patterns
Avoid these common mistakes in agent tool implementations:
- Insufficient context: Editing without fully understanding the code
- Over-verbosity: Including too much unchanged code in edits
- Premature editing: Making changes before properly exploring the codebase
- Context fragmentation: Reading small disconnected sections without building overall understanding
- Ignoring error recovery: Not implementing fallbacks when tools fail
Conclusion
Effective tool usage transforms AI agents from passive assistants to active agentic partners. By combining comprehensive tool definitions with clear usage protocols and error handling procedures, you can create agents that navigate, understand, and modify code with high accuracy and efficiency.