Overview
Forge allows you to create custom agents tailored to specific tasks. Custom agents can have specialized system prompts, tool configurations, and behaviors that make them experts in particular domains.Agent Structure
Custom agents in Forge are defined using a template structure that includes:- System Information: Context about the environment and available tools
- Tool Usage Instructions: How the agent should use tools
- Custom Rules: Project-specific guidelines
- Non-negotiable Rules: Core behaviors that must be followed
Creating a Custom Agent
<system_information>
{{> forge-partial-system-info.md }}
</system_information>
{{#if (not tool_supported)}}
<available_tools>
{{tool_information}}
</available_tools>
{{/if}}
<agent_role>
You are a specialized agent for [specific purpose].
Your primary responsibilities include:
- [Responsibility 1]
- [Responsibility 2]
- [Responsibility 3]
</agent_role>
<tool_usage_instructions>
- Use tools to accomplish tasks step-by-step
- Always verify your work using the appropriate tools
- [Custom tool usage guidelines]
</tool_usage_instructions>
{{#if custom_rules}}
<project_guidelines>
{{custom_rules}}
</project_guidelines>
{{/if}}
<non_negotiable_rules>
- [Core rule 1]
- [Core rule 2]
- Always cite code references using `filepath:line` format
</non_negotiable_rules>
# forge.yaml
custom_rules: |
1. Always add comprehensive error handling to any code you write.
2. Include unit tests for all new functions.
3. Follow our team's naming convention: camelCase for variables, PascalCase for classes.
4. Use our company's logging framework for all log statements.
// In agent_registry.rs
pub fn register_custom_agents(registry: &mut AgentRegistry) {
registry.register(
"my-custom-agent",
AgentDefinition {
name: "my-custom-agent",
description: "Specialized agent for specific tasks",
template: include_str!("templates/my-custom-agent.md"),
tools: vec!["read", "write", "bash"],
},
);
}
Template Variables
Forge provides several template variables you can use in your agent definitions:| Variable | Description |
|---|---|
{{tool_information}} | List of available tools and their descriptions |
{{custom_rules}} | Custom rules from forge.yaml |
{{> forge-partial-system-info.md}} | Standard system information partial |
{{#if tool_supported}} | Conditional for native tool support |
{{#if custom_rules}} | Conditional for custom rules presence |
Agent Configuration Options
Tool Access Control
Limit which tools an agent can access:Model Selection
Specify which model an agent should use:Custom Commands
Define shortcuts for common agent tasks:Example: Test Generation Agent
- Use descriptive variable names:
fixture,actual,expected - Prefer
assert_eq!on full objects rather than individual fields - Use
unwrap()in tests unless error details are needed - Create generic, reusable fixtures
- Use
derive_setters::Settersfor test data builders
- Read source code to understand what needs testing
- Analyze existing tests to match the project’s style
- Use
grepto find similar test patterns in the codebase - Write tests inline in the same file as the source code
- Always write tests in the same file as the code being tested
- Use pretty_assertions for all equality checks
- Follow the three-step test pattern without exception
- Never use placeholders in tests - write complete, runnable code