Skip to main content

Overview

The Agent Scheduler is the core intelligence component of RepoMaster that analyzes user input, creates structured task plans, and selects appropriate tools from the available toolkit. It operates in multiple distinct modes to fulfill user requirements through intelligent agent orchestration.

System Messages

The scheduler agent is configured with a comprehensive system message that defines its behavior and capabilities.

Scheduler Agent System Message

The scheduler operates with four distinct modes:
  1. Web Search Mode: Search the internet for real-time information, current events, or general knowledge
  2. Repository Mode: Search and use GitHub repositories or local repositories through hierarchical repository analysis
  3. General Code Assistant Mode: Provide general programming assistance without specific repositories

Mode Selection Strategy

# From agent_scheduler.py
scheduler_system_message = dedent("""Role: Enhanced Task Scheduler

Primary Responsibility:
The Enhanced Task Scheduler's main duty is to analyze user input, create a structured task plan 
based on available tools, and then select and call appropriate tools from the given set to fulfill 
user requirements.

Mode Selection Strategy:
- **Prioritize Web Search**: Before selecting a primary mode, determine if the user's query can be 
  directly answered using the `web_search` tool for real-time data, definitions, or general knowledge.
  
- **Repository Mode**: Use `run_repository_agent` for tasks involving code repositories. This unified 
  tool automatically detects whether the repository is a GitHub URL or local path. Triggered when:
  * User mentions local file paths, specific local directories
  * User wants to find existing solutions, mentions GitHub
  * User provides specific repository URLs or paths
  
- **General Code Assistant Mode**: Used for general programming questions, requests for code examples, 
  debugging help, or when no specific repository is mentioned.
""")

Working Process

1. Task Analysis and Initial Assessment

Upon receiving user input, the scheduler:
  • Thoroughly analyzes the requirements
  • Step 1 - Web Search Assessment: Determines if task requires real-time data or external knowledge
  • Step 2 - Plan Creation: Creates structured plan prioritizing repository-first approach when applicable

2. Tool Selection and Execution

The scheduler executes the plan by selecting one appropriate tool at a time:

Repository Mode (GitHub/Local)

  • Use run_repository_agent tool with repository URL or local path
  • Tool automatically detects repository type

General Code Assistant Mode

  • Use run_general_code_assistant tool for programming guidance

Web Search Mode

  • Use web_search tool for real-time information or general knowledge
  • Can be used standalone or as part of solving larger tasks

Repository-First Approach

  1. Repository Search: Use github_repo_search to find relevant repositories
  2. Sequential Execution: Select most promising repository and execute task
  3. Result Evaluation and Switching:
    • Evaluate if result satisfies requirements
    • If current repository fails, try next best repository
    • Continue until task completed or all viable options exhausted

3. Sequential Execution and Fallback

Subsequent tools are selected based on:
  1. Outcomes of previously executed tools
  2. Current state of the plan
  3. Capabilities of available tools
The scheduler is persistent in finding solutions - if one approach doesn’t work, it tries alternatives.

User Proxy System Message

# From agent_scheduler.py
user_proxy_system_message = dedent("""Role: Execution Proxy (User Proxy)

Primary Rules:
- Do not provide user-facing answers.
- Never paraphrase or repeat content already provided by scheduler_agent.
- Summarize tool outputs succinctly for the scheduler_agent only when needed
- If your candidate message would substantially repeat the last two messages, send exactly "TERMINATE"
- After scheduler_agent has delivered the final complete answer, respond with exactly "TERMINATE"
""")

Agent Initialization

Scheduler Agent

The scheduler agent is initialized as an ExtendedAssistantAgent:
def initialize_agents(self, **kwargs):
    """Initialize scheduler agent and user agent."""
    self.scheduler = ExtendedAssistantAgent(
        name="scheduler_agent",
        system_message=scheduler_system_message,
        is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").endswith("TERMINATE"),
        llm_config=self.llm_config,
    )
name
str
Agent name identifier: "scheduler_agent"
system_message
str
Comprehensive system message defining agent behavior and mode selection strategy
is_termination_msg
callable
Function to detect termination messages (checks if content ends with “TERMINATE”)
llm_config
dict
Language model configuration

User Proxy Agent

The user proxy agent is initialized as an ExtendedUserProxyAgent:
self.user_proxy = ExtendedUserProxyAgent(
    name="user_proxy",
    system_message=user_proxy_system_message,
    llm_config=self.llm_config,
    is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").endswith("TERMINATE"),
    human_input_mode="NEVER",
    max_consecutive_auto_reply=10,
    code_execution_config=self.code_execution_config,
)
name
str
Agent name identifier: "user_proxy"
system_message
str
System message defining execution proxy behavior
llm_config
dict
Language model configuration
is_termination_msg
callable
Function to detect termination messages
human_input_mode
str
Set to "NEVER" for fully autonomous operation
max_consecutive_auto_reply
int
Maximum number of consecutive automatic replies (default: 10)
code_execution_config
dict
Configuration for code execution environment

Tool Registration

The scheduler has access to four primary tools:
def register_tools(self):
    """Register the enhanced toolkit required by the agent."""
    register_toolkits(
        [
            self.web_search,                    # Web search mode
            self.run_repository_agent,          # Unified repository processing mode
            self.run_general_code_assistant,    # General code assistant mode
            self.github_repo_search,            # GitHub repository search
        ],
        self.scheduler,
        self.user_proxy,
    )

Available Tools

  1. web_search: Search the internet for real-time information
  2. run_repository_agent: Execute tasks using GitHub or local repositories
  3. run_general_code_assistant: Provide general programming assistance
  4. github_repo_search: Search for relevant GitHub repositories

Conversation Flow

Initiating a Chat

def solve_task_with_repo(self, task: str) -> str:
    """Main entry point for task solving"""
    initial_message = task
    
    # Start conversation
    chat_result = self.user_proxy.initiate_chat(
        self.scheduler,
        message=initial_message,
        max_turns=12,
        summary_method="reflection_with_llm",
        summary_args={
            'summary_prompt': "Summarize takeaway from the conversation and generate a complete and detailed report at last. Do not add any introductory phrases. The final answer should correspond to the user's question."
        }
    )
    
    final_answer = self._extract_final_answer(chat_result)
    return final_answer
message
str
Initial task message from the user
max_turns
int
Maximum number of conversation turns (default: 12)
summary_method
str
Method for generating conversation summary: "reflection_with_llm" or "last_msg"
summary_args
dict
Arguments for summary generation, including custom summary prompt

Extracting Final Answer

def _extract_final_answer(self, chat_result) -> str:
    """Extract final answer from chat history"""
    final_answer = chat_result.summary
    
    if isinstance(final_answer, dict):
        final_answer = final_answer['content']
    
    if final_answer is None:
        final_answer = ""
    final_answer = final_answer.strip().lstrip()
    
    messages = chat_result.chat_history
    final_content = messages[-1].get("content", "")
    if final_content:
        final_content = final_content.strip().lstrip()
    
    if final_answer == "":
        final_answer = final_content
    
    return final_answer

Usage Examples

Basic Task Execution

from src.core.agent_scheduler import RepoMasterAgent
from configs.oai_config import get_llm_config

# Setup
llm_config = get_llm_config()
code_execution_config = {
    "work_dir": "/path/to/work/dir",
    "use_docker": False
}

# Initialize agent
repo_master = RepoMasterAgent(
    llm_config=llm_config,
    code_execution_config=code_execution_config
)

# Execute task - scheduler automatically selects appropriate mode
result = repo_master.solve_task_with_repo(
    "What is the stock price of APPLE?"
)
print(result)

Repository Mode Example

# Task requiring repository exploration
result = repo_master.solve_task_with_repo(
    "Help me convert '/data/DeepResearcher.pdf' to markdown and save"
)
The scheduler will:
  1. Analyze the task
  2. Search for relevant PDF processing repositories
  3. Select the best repository
  4. Execute the conversion task
  5. Return the result

Direct Tool Access

While the scheduler typically orchestrates tool usage, tools can be called directly:
# Direct repository agent call
result = repo_master.run_repository_agent(
    task_description="Extract text from PDF",
    repository="https://github.com/spatie/pdf-to-text",
    input_data='[{"path": "input.pdf", "description": "PDF to process"}]'
)

# Direct general assistant call
result = repo_master.run_general_code_assistant(
    task_description="Write a function to merge CSV files",
    work_directory="/path/to/work"
)

Turn-taking and De-duplication

The scheduler implements intelligent turn-taking to avoid repetition:
  • Before sending any message, compares it with previous two messages
  • If response would substantially repeat previous content, skips it
  • If task has already been fully answered, replies with “TERMINATE”
  • Ensures efficient conversation flow and prevents circular discussions

Important Notes

  1. Always validates that local paths exist before using repository mode
  2. In general code assistant mode, creates practical, executable examples
  3. If a tool is successfully called, answers based on tool’s results and overall plan
  4. If no available tool can solve the task, generates answer based on knowledge
  5. When task is completed successfully, replies with “TERMINATE”

See Also

Build docs developers (and LLMs) love