|
| 1 | +--- |
| 2 | +title: Subagents |
| 3 | +description: Create subagents to compartmentalize tasks and create more complex agents |
| 4 | +--- |
| 5 | + |
| 6 | +# Sub-Agents & Agentic Structures in Latitude |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +Latitude’s agentic framework lets you build powerful, modular, and autonomous LLM workflows. This page covers how to design, implement, and orchestrate **sub-agents**, specialized agents that can be invoked by other agents, enabling complex, multi-step reasoning and tool use. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## What Are Agents and Sub-Agents? |
| 15 | + |
| 16 | +**Agent**: A `PromptL` prompt with `type: agent` that can plan, act, and iterate autonomously, calling tools or other agents as needed. |
| 17 | + |
| 18 | +**Sub-Agent**: Any agent that is exposed as a callable function/tool within another agent, allowing for modular, reusable, and composable workflows. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## When to Use Agents vs. Step Chains |
| 23 | + |
| 24 | +| Use an **Agent** when... | Use a **Chain** when... | |
| 25 | +| ------------------------------------------------ | ----------------------------------- | |
| 26 | +| The workflow is open-ended or branching | The workflow is strictly sequential | |
| 27 | +| The model must decide which tools/agents to call | The steps are always the same | |
| 28 | +| You want dynamic planning or iteration | You want deterministic, fixed steps | |
| 29 | + |
| 30 | +<Note> |
| 31 | +If you find yourself writing lots of conditional logic in a chain, consider switching to an agentic approach. |
| 32 | +</Note> |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Defining an Agent in PromptL |
| 37 | + |
| 38 | +To turn any prompt into an agent, add the following to your configuration header: |
| 39 | + |
| 40 | +```yaml |
| 41 | +--- |
| 42 | +type: agent |
| 43 | +provider: openai |
| 44 | +model: gpt-4o |
| 45 | +tools: |
| 46 | + - latitude/search |
| 47 | +maxSteps: 40 |
| 48 | +--- |
| 49 | +``` |
| 50 | + |
| 51 | +* `type: agent` enables agentic mode. |
| 52 | +* `tools:` lists external tools the agent can call. |
| 53 | +* `maxSteps:` (optional) limits the number of agent cycles. |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Exposing Sub-Agents |
| 58 | + |
| 59 | +You can expose other PromptL agent files as callable sub-agents using the `agents:` configuration key: |
| 60 | + |
| 61 | +```yaml |
| 62 | +--- |
| 63 | +type: agent |
| 64 | +agents: |
| 65 | + - agents/summarizer |
| 66 | + - agents/sentiment_analyzer |
| 67 | + - agents/researcher |
| 68 | +--- |
| 69 | +``` |
| 70 | + |
| 71 | +Each listed agent becomes available as a callable function/tool. |
| 72 | +Sub-agents can themselves call tools or other sub-agents, enabling **deep composition**. |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## Sub-Agent Design Patterns |
| 77 | + |
| 78 | +### 1. Single-Responsibility Helpers |
| 79 | + |
| 80 | +Keep sub-agents focused. Example: a summarizer agent that only summarizes text. |
| 81 | + |
| 82 | +```yaml |
| 83 | +--- |
| 84 | +type: agent |
| 85 | +schema: |
| 86 | + type: object |
| 87 | + properties: |
| 88 | + summary: { type: string } |
| 89 | + required: [summary] |
| 90 | +--- |
| 91 | +``` |
| 92 | + |
| 93 | +```promptl |
| 94 | +<system> |
| 95 | +You are a summarizer. Return a concise summary of the provided text. |
| 96 | +</system> |
| 97 | +
|
| 98 | +<user> |
| 99 | +{{ input_text }} |
| 100 | +</user> |
| 101 | +``` |
| 102 | +<Note> |
| 103 | +It is essential that you include parameters in subagents so that the main agent can send them information. |
| 104 | +</Note> |
| 105 | +--- |
| 106 | + |
| 107 | +### 2. Specialist Pool |
| 108 | + |
| 109 | +A generalist agent can delegate to a pool of specialists: |
| 110 | + |
| 111 | +```yaml |
| 112 | +--- |
| 113 | +type: agent |
| 114 | +agents: |
| 115 | + - agents/summarizer |
| 116 | + - agents/sentiment_analyzer |
| 117 | + - agents/fact_checker |
| 118 | +--- |
| 119 | +``` |
| 120 | + |
| 121 | +The agent can decide which specialist to call based on the task. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +### 3. Sequential Orchestration |
| 126 | + |
| 127 | +For strict order, use `<step>` blocks and specify which agent to call: |
| 128 | + |
| 129 | +```promptl |
| 130 | +<step agents={{ ["agents/parser"] }}> |
| 131 | +Parse the raw email and extract fields. |
| 132 | +</step> |
| 133 | +
|
| 134 | +<step agents={{ ["agents/team_lookup"] }}> |
| 135 | +Enrich team data via LinkedIn search. |
| 136 | +</step> |
| 137 | +
|
| 138 | +<step agents={{ ["agents/recommender"] }}> |
| 139 | +Produce a recommendation. |
| 140 | +</step> |
| 141 | +``` |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Agent Loop & Execution |
| 146 | + |
| 147 | +On each cycle, the agent can return: |
| 148 | + |
| 149 | +* **Tool calls only**: Latitude executes the tools, appends results, and continues. |
| 150 | +* **Text + tool calls**: Treated as internal thinking; tools are run. |
| 151 | +* **Text only**: The loop ends; this is the agent’s final answer. |
| 152 | + |
| 153 | +The loop stops when a text-only response is returned or `maxSteps` is reached. |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## Best Practices |
| 158 | + |
| 159 | +* **Single Responsibility**: Each sub-agent should do one thing well. |
| 160 | +* **Clear I/O**: Use `schema` to define expected outputs for each agent. |
| 161 | +* **Resource Awareness**: Each sub-agent call counts toward the parent’s `maxSteps`. |
| 162 | +* **Testing**: Use the Playground to debug and trace agent/sub-agent interactions. |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## Example: Multi-Agent Researcher |
| 167 | + |
| 168 | +### Main Agent Configuration |
| 169 | + |
| 170 | +```yaml |
| 171 | +--- |
| 172 | +type: agent |
| 173 | +agents: |
| 174 | + - agents/web_search |
| 175 | + - agents/summarizer |
| 176 | + - agents/citation_checker |
| 177 | +schema: |
| 178 | + type: object |
| 179 | + properties: |
| 180 | + report: { type: string } |
| 181 | +--- |
| 182 | +``` |
| 183 | + |
| 184 | +### Main Agent Prompt |
| 185 | + |
| 186 | +```promptl |
| 187 | +<system> |
| 188 | +You are a research assistant. Use your sub-agents to gather, summarize, and fact-check information before producing a final report. |
| 189 | +</system> |
| 190 | +<user> |
| 191 | +Research the latest trends in renewable energy. |
| 192 | +</user> |
| 193 | +``` |
| 194 | + |
| 195 | +### Sub-Agents |
| 196 | + |
| 197 | +* `agents/web_search`: Searches the web for relevant articles. |
| 198 | +* `agents/summarizer`: Summarizes article content. |
| 199 | +* `agents/citation_checker`: Verifies the credibility of sources. |
| 200 | + |
| 201 | +--- |
| 202 | + |
| 203 | +## Debugging & Tracing |
| 204 | + |
| 205 | +* Use the **Latitude Playground** to step through agent execution. |
| 206 | +* Inspect each sub-agent’s output and reasoning. |
| 207 | +* Adjust schemas and instructions for clarity and reliability. |
| 208 | + |
| 209 | +--- |
| 210 | + |
| 211 | +## Further Reading |
| 212 | + |
| 213 | +* [PromptL Agent Syntax](/docs/promptl/agent-syntax) |
| 214 | +* [Tool Integration](/docs/tools/overview) |
| 215 | +* [Chains vs. Agents](/docs/architecture/chains-vs-agents) |
| 216 | + |
| 217 | +--- |
| 218 | + |
| 219 | +## Examples |
| 220 | + |
| 221 | +To see how agents and subagents work in context you are welcome to check out the following example agents: |
| 222 | + |
| 223 | +1. Example 1: [Deep Search Agent](https://docs.latitude.so/examples/cases/deep-search) |
| 224 | + |
| 225 | +2. Example 2: [Customer Support Email Generator](https://docs.latitude.so/examples/cases/customer-support-email) |
| 226 | + |
| 227 | +--- |
| 228 | + |
| 229 | +## Summary |
| 230 | + |
| 231 | +Sub-agents and agentic structures in Latitude unlock modular, reusable, and powerful LLM workflows. By designing clear, focused agents and orchestrating them with the agentic loop, you can tackle complex, multi-stage tasks with reliability and transparency. |
0 commit comments