Skip to main content

Command Palette

Search for a command to run...

Let's Improve Our AI Agent for Snippet Generation... With a 2nd Agent!

Updated
4 min read
Let's Improve Our AI Agent for Snippet Generation... With a 2nd Agent!

Prerequisites: please read the previous post: Snippet Management and Generation with cagent

An extremely interesting feature of cagent is the ability to have multiple agents interact with each other. This means you can define multiple agents in the same YAML configuration file (agents that can use different LLMs), and these agents can communicate with each other (the main root agent will somehow transfer information and instructions to another agent based on user messages).

In my previous post, my main and only agent used the hf.co/menlo/jan-nano-gguf:q8_0 model which handled both tool call detection, MCP server communication, and snippet generation.

But there are models that are better suited for code generation, like the hf.co/quantfactory/deepseek-coder-7b-instruct-v1.5-gguf:q4_k_m model I recently discovered, which is very powerful for generating code (it's also larger than the jan-nano model). However, this model doesn't support tool calls (it can't detect the "intent" to call external tools).

So why not create a 2nd agent that would use this model for snippet generation, and let the 1st agent handle only tool call detection and MCP server communication?

Architecture Overview:

Let's see how to configure this.

Before starting, let's grab the new deepseek-coder-7b-instruct-v1.5-gguf:q4_k_m model (if not already done) using the command:

docker model pull hf.co/quantfactory/deepseek-coder-7b-instruct-v1.5-gguf:q4_k_m

bob.2.yaml

So I created a new bob.2.yaml file that defines 2 agents. Here are the main changes between bob.yaml and bob.2.yaml:

With bob.2.yaml, we move to a "hierarchical architecture" with 2 agents:

  • root agent (coordinator) using jan-nano

  • bob agent (specialized) using deepseek-coder

The role distribution is as follows:

Root agent:

  • Simpler description: "Main agent, uses MCP tools"

  • Short instruction: uses tools then transfers info to Bob agent

  • Has access to sub_agents: ["bob"]

Bob agent:

  • Takes all technical instructions from the old root agent

  • Specialized Golang expert

  • Receives information from root for follow-up operations

The changes consist of a separation of concerns: the root agent handles tools/searches, then Bob focuses on quality Golang code generation with a more specialized model.

And here's the complete content of the bob.2.yaml file:

  # cagent run bob.2.yaml
  agents:
    root:
      model: jan-nano
      description: Main agent, uses MCP tools
      instruction: |
        Use tools to accomplish the task, then transfer the info to the helper agent (Bob).

        If the user responds no to the execution of a tool, do not ask again
        If you have executed a tool, do not try to execute it again. Unless the user explicitly asks you to.

        If the person responds no to the confirmation, the cycle is terminated and the tool must no longer be offered, except upon new request
        Keep a history of refusals and stop any repeated suggestion on this same tool.
        Do not rephrase the tool suggestion after a refusal.

      tools: ["search_snippet", "write_file"]
      toolsets:
        - type: mcp
          remote:
            url: http://localhost:9011/mcp
            transport_type: streamable

      sub_agents: ["bob"]

    bob:
      model: deepseek-coder
      description: Bob, specialized agent, receives info from root
      instruction: |
        Use the information transmitted by the main agent (root), carry out the follow-up.

        Your name is Bob, you are a world class Golang expert.
        You write perfect, idiomatic, secure, efficient, well tested Golang code.
        You never write code in any other programming language.
        You always respond in markdown format with proper syntax highlighting for Golang.
        You always include comments and documentation for all functions and methods.
        You always follow best practices for error handling and logging.
        You always ensure your code is secure and free from common vulnerabilities.
        You always optimize your code for performance and efficiency.
        You always write clean, readable, and maintainable code.

  models:

    jan-nano:
      provider: dmr
      model: hf.co/menlo/jan-nano-gguf:q4_k_m
      temperature: 0.0
      max_tokens: 16384
      parallel_tool_calls: false

    deepseek-coder:
      provider: dmr
      model: hf.co/quantfactory/deepseek-coder-7b-instruct-v1.5-gguf:q4_k_m
      temperature: 0.0
      max_tokens: 16384

Starting the New Bob Agent

Run the following command in the directory where the bob.2.yaml file is located:

cagent run bob.2.yaml

Once again, rather than describing how to interact with Bob, I'm offering you another short video demonstration:

You just saw that with cagent it's very easy to evolve our AI assistant by adding a 2nd agent specialized in Golang code generation, using a model better suited to this task.

See you soon for new adventures and use cases with cagent!

All the source code is available here: https://github.com/k33g/bob-agent