Skip to content

Specialists

Specialists are domain-specific agents that handle particular types of tasks within the Bedrock Swarm system.

Core Concepts

What is a Specialist?

A specialist is a BedrockAgent configured with: - Specific domain expertise - Relevant tools for their domain - Clear system instructions - Focused responsibility

Built-in Specialists

Calculator Specialist

from bedrock_swarm.agents import BedrockAgent
from bedrock_swarm.tools import CalculatorTool

calculator = BedrockAgent(
    name="calculator",
    model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    tools=[CalculatorTool()],
    system_prompt="You are a mathematical specialist that excels at numerical calculations."
)

Time Expert

from bedrock_swarm.tools import CurrentTimeTool

time_expert = BedrockAgent(
    name="time_expert",
    model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    tools=[CurrentTimeTool()],
    system_prompt="You are a time and timezone expert."
)

Creating Custom Specialists

Basic Structure

from bedrock_swarm.agents import BedrockAgent
from bedrock_swarm.tools import BaseTool

# Create custom tool
class CustomTool(BaseTool):
    def __init__(self):
        self._name = "custom_tool"
        self._description = "Description of what the tool does"

    def _execute_impl(self, **kwargs):
        # Implementation
        pass

# Create specialist with custom tool
custom_specialist = BedrockAgent(
    name="custom_specialist",
    model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    tools=[CustomTool()],
    system_prompt="Specific instructions for this specialist"
)

Best Practices

  1. Focus and Responsibility
  2. Keep specialists focused on one domain
  3. Avoid overlapping responsibilities
  4. Clear system instructions

  5. Tool Design

  6. Tools should match specialist's domain
  7. Clear tool descriptions
  8. Proper error handling

  9. System Prompts

  10. Be specific about capabilities
  11. Define clear boundaries
  12. Include example interactions

Integration with Agency

from bedrock_swarm.agency import Agency

# Create specialists
specialists = [calculator, time_expert, custom_specialist]

# Create agency with specialists
agency = Agency(
    specialists=specialists,
    shared_instructions="Common instructions for all specialists"
)

Communication Flow

  1. Request Reception
  2. Coordinator receives user request
  3. Creates execution plan
  4. Identifies required specialists

  5. Task Execution

  6. Specialist receives task
  7. Uses appropriate tools
  8. Returns formatted results

  9. Result Integration

  10. Results passed between specialists
  11. Dependencies managed
  12. Final response formatted

Error Handling

Specialist Level

class CustomSpecialist(BedrockAgent):
    def handle_error(self, error):
        """Custom error handling logic"""
        self.log_error(error)
        return f"Error in specialist: {str(error)}"

Tool Level

class CustomTool(BaseTool):
    def _execute_impl(self, **kwargs):
        try:
            # Implementation
            pass
        except Exception as e:
            raise ValueError(f"Tool execution failed: {str(e)}")

Memory Management

Specialists can maintain their own memory:

from bedrock_swarm.memory import SimpleMemory

specialist = BedrockAgent(
    name="specialist",
    model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
    memory=SimpleMemory(),  # Specialist-specific memory
    tools=[CustomTool()]
)

Testing Specialists

def test_specialist():
    # Create specialist
    specialist = BedrockAgent(
        name="test_specialist",
        model_id="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
        tools=[CustomTool()]
    )

    # Test basic functionality
    response = specialist.generate("Test request")
    assert response is not None

    # Test tool execution
    tool_response = specialist.tools["custom_tool"].execute(arg="test")
    assert tool_response is not None