# Agents

> An Agent is a tool that queries an LLM, equipped with other tools, to accomplish tasks.

GenAIScript defines an **agent** as a [tool](/genaiscript/reference/scripts/tools) that runs an [inline prompt](/genaiscript/reference/scripts/inline-prompts) to accomplish a task. The agent’s LLM is typically augmented with additional tools and a memory.

```js
script({
    // use all agents
    tools: "agent",
})


// agent git to get the commits
// agent interpreter to run python code
$`Do a statistical analysis of the last commits`
```

**GenAIScript does *not* implement any agentic workflow or decision.** It relies entirely on [tools](/genaiscript/reference/scripts/tools) support built into the LLMs.

## Agent = LLM + Tools

[Section titled “Agent = LLM + Tools”](#agent--llm--tools)

Let’s take a look at the `agent_git` example that query a git repository. This agent is registered as a `tool` and can be used in the LLM prompt. When the LLM needs information about something like “summarize changes in the current branch”, it will call the `agent_git` tool with the query `get changes in the current branch`.

The `agent_git` tool itself has access to various git dedicated tools like `git branch`, `git diff` that it can use to solve. It will have to resolve the current and default branch, compute a diff and return it to the main LLM.

![](<data:image/svg+xml,%3csvg aria-roledescription='flowchart-v2' role='graphics-document document' viewBox='0 0 563.6875 379.125' style='max-width: 563.6875px%3b' class='flowchart' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg' width='100%25' id='mermaid-0'%3e%3cstyle%3e%23mermaid-0%7bfont-family:arial%2csans-serif%3bfont-size:16px%3bfill:%23333%3b%7d%40keyframes edge-animation-frame%7bfrom%7bstroke-dashoffset:0%3b%7d%7d%40keyframes dash%7bto%7bstroke-dashoffset:0%3b%7d%7d%23mermaid-0 .edge-animation-slow%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 50s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-0 .edge-animation-fast%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 20s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-0 .error-icon%7bfill:%23552222%3b%7d%23mermaid-0 .error-text%7bfill:%23552222%3bstroke:%23552222%3b%7d%23mermaid-0 .edge-thickness-normal%7bstroke-width:1px%3b%7d%23mermaid-0 .edge-thickness-thick%7bstroke-width:3.5px%3b%7d%23mermaid-0 .edge-pattern-solid%7bstroke-dasharray:0%3b%7d%23mermaid-0 .edge-thickness-invisible%7bstroke-width:0%3bfill:none%3b%7d%23mermaid-0 .edge-pattern-dashed%7bstroke-dasharray:3%3b%7d%23mermaid-0 .edge-pattern-dotted%7bstroke-dasharray:2%3b%7d%23mermaid-0 .marker%7bfill:%23333333%3bstroke:%23333333%3b%7d%23mermaid-0 .marker.cross%7bstroke:%23333333%3b%7d%23mermaid-0 svg%7bfont-family:arial%2csans-serif%3bfont-size:16px%3b%7d%23mermaid-0 p%7bmargin:0%3b%7d%23mermaid-0 .label%7bfont-family:arial%2csans-serif%3bcolor:%23333%3b%7d%23mermaid-0 .cluster-label text%7bfill:%23333%3b%7d%23mermaid-0 .cluster-label span%7bcolor:%23333%3b%7d%23mermaid-0 .cluster-label span p%7bbackground-color:transparent%3b%7d%23mermaid-0 .label text%2c%23mermaid-0 span%7bfill:%23333%3bcolor:%23333%3b%7d%23mermaid-0 .node rect%2c%23mermaid-0 .node circle%2c%23mermaid-0 .node ellipse%2c%23mermaid-0 .node polygon%2c%23mermaid-0 .node path%7bfill:%23ECECFF%3bstroke:%239370DB%3bstroke-width:1px%3b%7d%23mermaid-0 .rough-node .label text%2c%23mermaid-0 .node .label text%2c%23mermaid-0 .image-shape .label%2c%23mermaid-0 .icon-shape .label%7btext-anchor:middle%3b%7d%23mermaid-0 .node .katex path%7bfill:black%3bstroke:black%3bstroke-width:1px%3b%7d%23mermaid-0 .rough-node .label%2c%23mermaid-0 .node .label%2c%23mermaid-0 .image-shape .label%2c%23mermaid-0 .icon-shape .label%7btext-align:center%3b%7d%23mermaid-0 .node.clickable%7bcursor:pointer%3b%7d%23mermaid-0 .root .anchor path%7bfill:%23333333!important%3bstroke-width:0%3bstroke:%23333333%3b%7d%23mermaid-0 .arrowheadPath%7bfill:%23333333%3b%7d%23mermaid-0 .edgePath .path%7bstroke:%23333333%3bstroke-width:2.0px%3b%7d%23mermaid-0 .flowchart-link%7bstroke:%23333333%3bfill:none%3b%7d%23mermaid-0 .edgeLabel%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-0 .edgeLabel p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-0 .edgeLabel rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-0 .labelBkg%7bbackground-color:rgba(232%2c 232%2c 232%2c 0.5)%3b%7d%23mermaid-0 .cluster rect%7bfill:%23ffffde%3bstroke:%23aaaa33%3bstroke-width:1px%3b%7d%23mermaid-0 .cluster text%7bfill:%23333%3b%7d%23mermaid-0 .cluster span%7bcolor:%23333%3b%7d%23mermaid-0 div.mermaidTooltip%7bposition:absolute%3btext-align:center%3bmax-width:200px%3bpadding:2px%3bfont-family:arial%2csans-serif%3bfont-size:12px%3bbackground:hsl(80%2c 100%25%2c 96.2745098039%25)%3bborder:1px solid %23aaaa33%3bborder-radius:2px%3bpointer-events:none%3bz-index:100%3b%7d%23mermaid-0 .flowchartTitleText%7btext-anchor:middle%3bfont-size:18px%3bfill:%23333%3b%7d%23mermaid-0 rect.text%7bfill:none%3bstroke-width:0%3b%7d%23mermaid-0 .icon-shape%2c%23mermaid-0 .image-shape%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-0 .icon-shape p%2c%23mermaid-0 .image-shape p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bpadding:2px%3b%7d%23mermaid-0 .icon-shape rect%2c%23mermaid-0 .image-shape rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-0 .label-icon%7bdisplay:inline-block%3bheight:1em%3boverflow:visible%3bvertical-align:-0.125em%3b%7d%23mermaid-0 .node .label-icon path%7bfill:currentColor%3bstroke:revert%3bstroke-width:revert%3b%7d%23mermaid-0 :root%7b--mermaid-font-family:arial%2csans-serif%3b%7d%3c/style%3e%3cg%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-0_flowchart-v2-pointEnd'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 0 L 10 5 L 0 10 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='4.5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-0_flowchart-v2-pointStart'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 5 L 10 10 L 10 0 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='11' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-0_flowchart-v2-circleEnd'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='-1' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-0_flowchart-v2-circleStart'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='12' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-0_flowchart-v2-crossEnd'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='-1' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-0_flowchart-v2-crossStart'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cg class='root'%3e%3cg class='clusters'/%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-0_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_query_LLM_0' d='M249.156%2c39.5L271.724%2c39.5C294.292%2c39.5%2c339.427%2c39.5%2c383.229%2c57.467C427.03%2c75.434%2c469.498%2c111.367%2c490.732%2c129.334L511.966%2c147.301'/%3e%3cpath marker-end='url(%23mermaid-0_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_LLM_agent_git_0' d='M509.563%2c182.738L488.729%2c198.958C467.896%2c215.179%2c426.229%2c247.621%2c385.223%2c261.107C344.217%2c274.593%2c303.872%2c269.123%2c283.699%2c266.388L263.526%2c263.653'/%3e%3cpath marker-end='url(%23mermaid-0_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_git_LLM_0' d='M259.563%2c205.295L280.396%2c198.543C301.229%2c191.791%2c342.896%2c178.286%2c383.896%2c171.534C424.896%2c164.781%2c465.229%2c164.781%2c485.396%2c164.781L505.563%2c164.781'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(384.5625%2c 280.0625)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3eget changes in current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(384.5625%2c 164.78125)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3ediff %2bmain.ts -main.ts...%2b new code%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(0%2c 113)' class='root'%3e%3cg class='clusters'%3e%3cg data-look='classic' id='agent_git' class='cluster'%3e%3crect height='250.125' width='251.5625' y='8' x='8' style=''/%3e%3cg transform='translate(103.0859375%2c 8)' class='cluster-label'%3e%3cforeignObject height='24' width='61.390625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eagent git%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-0_flowchart-v2-pointEnd)' marker-start='url(%23mermaid-0_flowchart-v2-pointStart)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_git_LLM_git_tools_0' d='M133.781%2c95.625L133.781%2c101.208C133.781%2c106.792%2c133.781%2c117.958%2c133.781%2c129.125C133.781%2c140.292%2c133.781%2c151.458%2c133.781%2c157.042L133.781%2c162.625'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(133.78125%2c 68.5625)' id='flowchart-agent_git_LLM-6' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(133.78125%2c 193.625)' id='flowchart-git_tools-7' class='node default'%3e%3crect height='54' width='181.5625' y='-27' x='-90.78125' style='' class='basic label-container'/%3e%3cg transform='translate(-60.78125%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='121.5625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3egit branch%2c git diff%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg transform='translate(133.78125%2c 39.5)' id='flowchart-query-0' class='node default'%3e%3crect height='63' width='230.75' y='-31.5' x='-115.375' ry='31.5' rx='31.5' style='' class='basic label-container'/%3e%3cg transform='translate(-100%2c -24)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3esummarize changes in the current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(532.625%2c 164.78125)' id='flowchart-LLM-1' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e>)

## Agent vs Tools

[Section titled “Agent vs Tools”](#agent-vs-tools)

An “agent” is a tool that queries an LLM, equipped with other tools, to accomplish tasks. It is a higher-level abstraction that can be used to group multiple tools together. In some scenarios, you might decide to remove that abstraction and skip the agent by “giving” the tools to the calling LLM. In this simple example, you could also decide to flatten this tree and give access to the git tools to the main LLM and skip the agent.

![](<data:image/svg+xml,%3csvg aria-roledescription='flowchart-v2' role='graphics-document document' viewBox='0 0 574.4375 79' style='max-width: 574.4375px%3b' class='flowchart' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg' width='100%25' id='mermaid-1'%3e%3cstyle%3e%23mermaid-1%7bfont-family:arial%2csans-serif%3bfont-size:16px%3bfill:%23333%3b%7d%40keyframes edge-animation-frame%7bfrom%7bstroke-dashoffset:0%3b%7d%7d%40keyframes dash%7bto%7bstroke-dashoffset:0%3b%7d%7d%23mermaid-1 .edge-animation-slow%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 50s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-1 .edge-animation-fast%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 20s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-1 .error-icon%7bfill:%23552222%3b%7d%23mermaid-1 .error-text%7bfill:%23552222%3bstroke:%23552222%3b%7d%23mermaid-1 .edge-thickness-normal%7bstroke-width:1px%3b%7d%23mermaid-1 .edge-thickness-thick%7bstroke-width:3.5px%3b%7d%23mermaid-1 .edge-pattern-solid%7bstroke-dasharray:0%3b%7d%23mermaid-1 .edge-thickness-invisible%7bstroke-width:0%3bfill:none%3b%7d%23mermaid-1 .edge-pattern-dashed%7bstroke-dasharray:3%3b%7d%23mermaid-1 .edge-pattern-dotted%7bstroke-dasharray:2%3b%7d%23mermaid-1 .marker%7bfill:%23333333%3bstroke:%23333333%3b%7d%23mermaid-1 .marker.cross%7bstroke:%23333333%3b%7d%23mermaid-1 svg%7bfont-family:arial%2csans-serif%3bfont-size:16px%3b%7d%23mermaid-1 p%7bmargin:0%3b%7d%23mermaid-1 .label%7bfont-family:arial%2csans-serif%3bcolor:%23333%3b%7d%23mermaid-1 .cluster-label text%7bfill:%23333%3b%7d%23mermaid-1 .cluster-label span%7bcolor:%23333%3b%7d%23mermaid-1 .cluster-label span p%7bbackground-color:transparent%3b%7d%23mermaid-1 .label text%2c%23mermaid-1 span%7bfill:%23333%3bcolor:%23333%3b%7d%23mermaid-1 .node rect%2c%23mermaid-1 .node circle%2c%23mermaid-1 .node ellipse%2c%23mermaid-1 .node polygon%2c%23mermaid-1 .node path%7bfill:%23ECECFF%3bstroke:%239370DB%3bstroke-width:1px%3b%7d%23mermaid-1 .rough-node .label text%2c%23mermaid-1 .node .label text%2c%23mermaid-1 .image-shape .label%2c%23mermaid-1 .icon-shape .label%7btext-anchor:middle%3b%7d%23mermaid-1 .node .katex path%7bfill:black%3bstroke:black%3bstroke-width:1px%3b%7d%23mermaid-1 .rough-node .label%2c%23mermaid-1 .node .label%2c%23mermaid-1 .image-shape .label%2c%23mermaid-1 .icon-shape .label%7btext-align:center%3b%7d%23mermaid-1 .node.clickable%7bcursor:pointer%3b%7d%23mermaid-1 .root .anchor path%7bfill:%23333333!important%3bstroke-width:0%3bstroke:%23333333%3b%7d%23mermaid-1 .arrowheadPath%7bfill:%23333333%3b%7d%23mermaid-1 .edgePath .path%7bstroke:%23333333%3bstroke-width:2.0px%3b%7d%23mermaid-1 .flowchart-link%7bstroke:%23333333%3bfill:none%3b%7d%23mermaid-1 .edgeLabel%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-1 .edgeLabel p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-1 .edgeLabel rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-1 .labelBkg%7bbackground-color:rgba(232%2c 232%2c 232%2c 0.5)%3b%7d%23mermaid-1 .cluster rect%7bfill:%23ffffde%3bstroke:%23aaaa33%3bstroke-width:1px%3b%7d%23mermaid-1 .cluster text%7bfill:%23333%3b%7d%23mermaid-1 .cluster span%7bcolor:%23333%3b%7d%23mermaid-1 div.mermaidTooltip%7bposition:absolute%3btext-align:center%3bmax-width:200px%3bpadding:2px%3bfont-family:arial%2csans-serif%3bfont-size:12px%3bbackground:hsl(80%2c 100%25%2c 96.2745098039%25)%3bborder:1px solid %23aaaa33%3bborder-radius:2px%3bpointer-events:none%3bz-index:100%3b%7d%23mermaid-1 .flowchartTitleText%7btext-anchor:middle%3bfont-size:18px%3bfill:%23333%3b%7d%23mermaid-1 rect.text%7bfill:none%3bstroke-width:0%3b%7d%23mermaid-1 .icon-shape%2c%23mermaid-1 .image-shape%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-1 .icon-shape p%2c%23mermaid-1 .image-shape p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bpadding:2px%3b%7d%23mermaid-1 .icon-shape rect%2c%23mermaid-1 .image-shape rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-1 .label-icon%7bdisplay:inline-block%3bheight:1em%3boverflow:visible%3bvertical-align:-0.125em%3b%7d%23mermaid-1 .node .label-icon path%7bfill:currentColor%3bstroke:revert%3bstroke-width:revert%3b%7d%23mermaid-1 :root%7b--mermaid-font-family:arial%2csans-serif%3b%7d%3c/style%3e%3cg%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-1_flowchart-v2-pointEnd'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 0 L 10 5 L 0 10 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='4.5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-1_flowchart-v2-pointStart'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 5 L 10 10 L 10 0 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='11' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-1_flowchart-v2-circleEnd'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='-1' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-1_flowchart-v2-circleStart'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='12' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-1_flowchart-v2-crossEnd'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='-1' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-1_flowchart-v2-crossStart'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cg class='root'%3e%3cg class='clusters'/%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-1_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_query_LLM_0' d='M238.75%2c39.5L242.917%2c39.5C247.083%2c39.5%2c255.417%2c39.5%2c263.083%2c39.5C270.75%2c39.5%2c277.75%2c39.5%2c281.25%2c39.5L284.75%2c39.5'/%3e%3cpath marker-end='url(%23mermaid-1_flowchart-v2-pointEnd)' marker-start='url(%23mermaid-1_flowchart-v2-pointStart)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_LLM_git_tools_0' d='M338.875%2c39.5L342.375%2c39.5C345.875%2c39.5%2c352.875%2c39.5%2c359.875%2c39.5C366.875%2c39.5%2c373.875%2c39.5%2c377.375%2c39.5L380.875%2c39.5'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(123.375%2c 39.5)' id='flowchart-query-0' class='node default'%3e%3crect height='63' width='230.75' y='-31.5' x='-115.375' ry='31.5' rx='31.5' style='' class='basic label-container'/%3e%3cg transform='translate(-100%2c -24)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3esummarize changes in the current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(311.8125%2c 39.5)' id='flowchart-LLM-1' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(475.65625%2c 39.5)' id='flowchart-git_tools-3' class='node default'%3e%3crect height='54' width='181.5625' y='-27' x='-90.78125' style='' class='basic label-container'/%3e%3cg transform='translate(-60.78125%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='121.5625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3egit branch%2c git diff%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e>)

However, the agent abstraction becomes useful when you start to have too many functions or to keep the chat conversation length small as each agent LLM call gets “compressed” to the agent response.

## Multiple Agents

[Section titled “Multiple Agents”](#multiple-agents)

Let’s take a look at a more complex example where multiple agents are involved in the conversation. In this case, we would like to investigate why a GitHub action failed. It involves the `agent_git` and the `agent_github` agents. The `agent_github` can query workflows, runs, jobs, logs and the `agent_git` can query the git repository.

![](<data:image/svg+xml,%3csvg aria-roledescription='flowchart-v2' role='graphics-document document' viewBox='0 0 646.49609375 806.375' style='max-width: 646.49609375px%3b' class='flowchart' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg' width='100%25' id='mermaid-2'%3e%3cstyle%3e%23mermaid-2%7bfont-family:arial%2csans-serif%3bfont-size:16px%3bfill:%23333%3b%7d%40keyframes edge-animation-frame%7bfrom%7bstroke-dashoffset:0%3b%7d%7d%40keyframes dash%7bto%7bstroke-dashoffset:0%3b%7d%7d%23mermaid-2 .edge-animation-slow%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 50s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-2 .edge-animation-fast%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 20s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-2 .error-icon%7bfill:%23552222%3b%7d%23mermaid-2 .error-text%7bfill:%23552222%3bstroke:%23552222%3b%7d%23mermaid-2 .edge-thickness-normal%7bstroke-width:1px%3b%7d%23mermaid-2 .edge-thickness-thick%7bstroke-width:3.5px%3b%7d%23mermaid-2 .edge-pattern-solid%7bstroke-dasharray:0%3b%7d%23mermaid-2 .edge-thickness-invisible%7bstroke-width:0%3bfill:none%3b%7d%23mermaid-2 .edge-pattern-dashed%7bstroke-dasharray:3%3b%7d%23mermaid-2 .edge-pattern-dotted%7bstroke-dasharray:2%3b%7d%23mermaid-2 .marker%7bfill:%23333333%3bstroke:%23333333%3b%7d%23mermaid-2 .marker.cross%7bstroke:%23333333%3b%7d%23mermaid-2 svg%7bfont-family:arial%2csans-serif%3bfont-size:16px%3b%7d%23mermaid-2 p%7bmargin:0%3b%7d%23mermaid-2 .label%7bfont-family:arial%2csans-serif%3bcolor:%23333%3b%7d%23mermaid-2 .cluster-label text%7bfill:%23333%3b%7d%23mermaid-2 .cluster-label span%7bcolor:%23333%3b%7d%23mermaid-2 .cluster-label span p%7bbackground-color:transparent%3b%7d%23mermaid-2 .label text%2c%23mermaid-2 span%7bfill:%23333%3bcolor:%23333%3b%7d%23mermaid-2 .node rect%2c%23mermaid-2 .node circle%2c%23mermaid-2 .node ellipse%2c%23mermaid-2 .node polygon%2c%23mermaid-2 .node path%7bfill:%23ECECFF%3bstroke:%239370DB%3bstroke-width:1px%3b%7d%23mermaid-2 .rough-node .label text%2c%23mermaid-2 .node .label text%2c%23mermaid-2 .image-shape .label%2c%23mermaid-2 .icon-shape .label%7btext-anchor:middle%3b%7d%23mermaid-2 .node .katex path%7bfill:black%3bstroke:black%3bstroke-width:1px%3b%7d%23mermaid-2 .rough-node .label%2c%23mermaid-2 .node .label%2c%23mermaid-2 .image-shape .label%2c%23mermaid-2 .icon-shape .label%7btext-align:center%3b%7d%23mermaid-2 .node.clickable%7bcursor:pointer%3b%7d%23mermaid-2 .root .anchor path%7bfill:%23333333!important%3bstroke-width:0%3bstroke:%23333333%3b%7d%23mermaid-2 .arrowheadPath%7bfill:%23333333%3b%7d%23mermaid-2 .edgePath .path%7bstroke:%23333333%3bstroke-width:2.0px%3b%7d%23mermaid-2 .flowchart-link%7bstroke:%23333333%3bfill:none%3b%7d%23mermaid-2 .edgeLabel%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-2 .edgeLabel p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-2 .edgeLabel rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-2 .labelBkg%7bbackground-color:rgba(232%2c 232%2c 232%2c 0.5)%3b%7d%23mermaid-2 .cluster rect%7bfill:%23ffffde%3bstroke:%23aaaa33%3bstroke-width:1px%3b%7d%23mermaid-2 .cluster text%7bfill:%23333%3b%7d%23mermaid-2 .cluster span%7bcolor:%23333%3b%7d%23mermaid-2 div.mermaidTooltip%7bposition:absolute%3btext-align:center%3bmax-width:200px%3bpadding:2px%3bfont-family:arial%2csans-serif%3bfont-size:12px%3bbackground:hsl(80%2c 100%25%2c 96.2745098039%25)%3bborder:1px solid %23aaaa33%3bborder-radius:2px%3bpointer-events:none%3bz-index:100%3b%7d%23mermaid-2 .flowchartTitleText%7btext-anchor:middle%3bfont-size:18px%3bfill:%23333%3b%7d%23mermaid-2 rect.text%7bfill:none%3bstroke-width:0%3b%7d%23mermaid-2 .icon-shape%2c%23mermaid-2 .image-shape%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-2 .icon-shape p%2c%23mermaid-2 .image-shape p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bpadding:2px%3b%7d%23mermaid-2 .icon-shape rect%2c%23mermaid-2 .image-shape rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-2 .label-icon%7bdisplay:inline-block%3bheight:1em%3boverflow:visible%3bvertical-align:-0.125em%3b%7d%23mermaid-2 .node .label-icon path%7bfill:currentColor%3bstroke:revert%3bstroke-width:revert%3b%7d%23mermaid-2 :root%7b--mermaid-font-family:arial%2csans-serif%3b%7d%3c/style%3e%3cg%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-2_flowchart-v2-pointEnd'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 0 L 10 5 L 0 10 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='4.5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-2_flowchart-v2-pointStart'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 5 L 10 10 L 10 0 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='11' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-2_flowchart-v2-circleEnd'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='-1' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-2_flowchart-v2-circleStart'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='12' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-2_flowchart-v2-crossEnd'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='-1' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-2_flowchart-v2-crossStart'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cg class='root'%3e%3cg class='clusters'/%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_query_LLM_0' d='M123.375%2c176.563L123.375%2c204.323C123.375%2c232.083%2c123.375%2c287.604%2c157.273%2c327.819C191.172%2c368.035%2c258.969%2c392.945%2c292.867%2c405.399L326.766%2c417.854'/%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_LLM_agent_git_0' d='M329.105%2c436.761L304.015%2c447.175C278.924%2c457.59%2c228.743%2c478.42%2c211.327%2c496.53C193.911%2c514.639%2c209.26%2c530.029%2c216.935%2c537.723L224.609%2c545.418'/%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_git_LLM_0' d='M385.502%2c548.25L387.679%2c540.083C389.856%2c531.917%2c394.209%2c515.583%2c391.489%2c499.811C388.769%2c484.038%2c378.975%2c468.826%2c374.078%2c461.219L369.181%2c453.613'/%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_LLM_agent_github_0' d='M375.23%2c417.645L405.247%2c405.225C435.264%2c392.805%2c495.298%2c367.965%2c520.405%2c345.972C545.512%2c323.978%2c535.692%2c304.831%2c530.782%2c295.258L525.872%2c285.684'/%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_github_LLM_0' d='M383.454%2c282.125L378.239%2c292.292C373.025%2c302.458%2c362.597%2c322.792%2c357.382%2c342.458C352.168%2c362.125%2c352.168%2c381.125%2c352.168%2c390.625L352.168%2c400.125'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(178.5625%2c 499.25)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3eget changes in current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(398.5625%2c 499.25)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3ediff %2bmain.ts -main.ts...%2b new code%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(555.33203125%2c 343.125)' class='edgeLabel'%3e%3cg transform='translate(-83.1640625%2c -12)' class='label'%3e%3cforeignObject height='24' width='166.328125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3equery the last failed run%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(352.16796875%2c 343.125)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -36)' class='label'%3e%3cforeignObject height='72' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3ecommit failed_sha is responsible%5cnsuccess_sha is last known good%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(280.75%2c 0)' class='root'%3e%3cg class='clusters'%3e%3cg data-look='classic' id='agent_github' class='cluster'%3e%3crect height='274.125' width='330' y='8' x='8' style=''/%3e%3cg transform='translate(128.9609375%2c 8)' class='cluster-label'%3e%3cforeignObject height='24' width='88.078125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eagent github%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' marker-start='url(%23mermaid-2_flowchart-v2-pointStart)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_github_LLM_github_tools_0' d='M173%2c95.625L173%2c101.208C173%2c106.792%2c173%2c117.958%2c173%2c129.125C173%2c140.292%2c173%2c151.458%2c173%2c157.042L173%2c162.625'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(173%2c 68.5625)' id='flowchart-agent_github_LLM-12' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(173%2c 205.625)' id='flowchart-github_tools-13' class='node default'%3e%3crect height='78' width='260' y='-39' x='-130' style='' class='basic label-container'/%3e%3cg transform='translate(-100%2c -24)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3elist workflow runs%2c list jobs%2c diff job logs%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg transform='translate(218.38671875%2c 540.25)' class='root'%3e%3cg class='clusters'%3e%3cg data-look='classic' id='agent_git' class='cluster'%3e%3crect height='250.125' width='251.5625' y='8' x='8' style=''/%3e%3cg transform='translate(103.0859375%2c 8)' class='cluster-label'%3e%3cforeignObject height='24' width='61.390625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eagent git%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-2_flowchart-v2-pointEnd)' marker-start='url(%23mermaid-2_flowchart-v2-pointStart)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_git_LLM_git_tools_0' d='M133.781%2c95.625L133.781%2c101.208C133.781%2c106.792%2c133.781%2c117.958%2c133.781%2c129.125C133.781%2c140.292%2c133.781%2c151.458%2c133.781%2c157.042L133.781%2c162.625'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(133.78125%2c 68.5625)' id='flowchart-agent_git_LLM-6' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(133.78125%2c 193.625)' id='flowchart-git_tools-7' class='node default'%3e%3crect height='54' width='181.5625' y='-27' x='-90.78125' style='' class='basic label-container'/%3e%3cg transform='translate(-60.78125%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='121.5625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3egit branch%2c git diff%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg transform='translate(123.375%2c 145.0625)' id='flowchart-query-0' class='node default'%3e%3crect height='63' width='230.75' y='-31.5' x='-115.375' ry='31.5' rx='31.5' style='' class='basic label-container'/%3e%3cg transform='translate(-100%2c -24)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3esummarize changes in the current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(352.16796875%2c 427.1875)' id='flowchart-LLM-1' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e>)

## Memory

[Section titled “Memory”](#memory)

All agents are equipped with a **memory** that allows them to share information horizontally across all conversations.

The memory is a log that stores all `agent / query / answer` interactions. When generating the prompt for an agent, the memory is first prompted (using a small LLM) to extract relevant information and that information is passed to the agent query.

```txt
ask agent about "query":
    wisdom = find info in memory about "query"
    agent answer "query" using your tools and information in "wisdom"
```

![](<data:image/svg+xml,%3csvg aria-roledescription='flowchart-v2' role='graphics-document document' viewBox='0 0 981.7109375 907.6777954101562' style='max-width: 981.7109375px%3b' class='flowchart' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg' width='100%25' id='mermaid-3'%3e%3cstyle%3e%23mermaid-3%7bfont-family:arial%2csans-serif%3bfont-size:16px%3bfill:%23333%3b%7d%40keyframes edge-animation-frame%7bfrom%7bstroke-dashoffset:0%3b%7d%7d%40keyframes dash%7bto%7bstroke-dashoffset:0%3b%7d%7d%23mermaid-3 .edge-animation-slow%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 50s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-3 .edge-animation-fast%7bstroke-dasharray:9%2c5!important%3bstroke-dashoffset:900%3banimation:dash 20s linear infinite%3bstroke-linecap:round%3b%7d%23mermaid-3 .error-icon%7bfill:%23552222%3b%7d%23mermaid-3 .error-text%7bfill:%23552222%3bstroke:%23552222%3b%7d%23mermaid-3 .edge-thickness-normal%7bstroke-width:1px%3b%7d%23mermaid-3 .edge-thickness-thick%7bstroke-width:3.5px%3b%7d%23mermaid-3 .edge-pattern-solid%7bstroke-dasharray:0%3b%7d%23mermaid-3 .edge-thickness-invisible%7bstroke-width:0%3bfill:none%3b%7d%23mermaid-3 .edge-pattern-dashed%7bstroke-dasharray:3%3b%7d%23mermaid-3 .edge-pattern-dotted%7bstroke-dasharray:2%3b%7d%23mermaid-3 .marker%7bfill:%23333333%3bstroke:%23333333%3b%7d%23mermaid-3 .marker.cross%7bstroke:%23333333%3b%7d%23mermaid-3 svg%7bfont-family:arial%2csans-serif%3bfont-size:16px%3b%7d%23mermaid-3 p%7bmargin:0%3b%7d%23mermaid-3 .label%7bfont-family:arial%2csans-serif%3bcolor:%23333%3b%7d%23mermaid-3 .cluster-label text%7bfill:%23333%3b%7d%23mermaid-3 .cluster-label span%7bcolor:%23333%3b%7d%23mermaid-3 .cluster-label span p%7bbackground-color:transparent%3b%7d%23mermaid-3 .label text%2c%23mermaid-3 span%7bfill:%23333%3bcolor:%23333%3b%7d%23mermaid-3 .node rect%2c%23mermaid-3 .node circle%2c%23mermaid-3 .node ellipse%2c%23mermaid-3 .node polygon%2c%23mermaid-3 .node path%7bfill:%23ECECFF%3bstroke:%239370DB%3bstroke-width:1px%3b%7d%23mermaid-3 .rough-node .label text%2c%23mermaid-3 .node .label text%2c%23mermaid-3 .image-shape .label%2c%23mermaid-3 .icon-shape .label%7btext-anchor:middle%3b%7d%23mermaid-3 .node .katex path%7bfill:black%3bstroke:black%3bstroke-width:1px%3b%7d%23mermaid-3 .rough-node .label%2c%23mermaid-3 .node .label%2c%23mermaid-3 .image-shape .label%2c%23mermaid-3 .icon-shape .label%7btext-align:center%3b%7d%23mermaid-3 .node.clickable%7bcursor:pointer%3b%7d%23mermaid-3 .root .anchor path%7bfill:%23333333!important%3bstroke-width:0%3bstroke:%23333333%3b%7d%23mermaid-3 .arrowheadPath%7bfill:%23333333%3b%7d%23mermaid-3 .edgePath .path%7bstroke:%23333333%3bstroke-width:2.0px%3b%7d%23mermaid-3 .flowchart-link%7bstroke:%23333333%3bfill:none%3b%7d%23mermaid-3 .edgeLabel%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-3 .edgeLabel p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-3 .edgeLabel rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-3 .labelBkg%7bbackground-color:rgba(232%2c 232%2c 232%2c 0.5)%3b%7d%23mermaid-3 .cluster rect%7bfill:%23ffffde%3bstroke:%23aaaa33%3bstroke-width:1px%3b%7d%23mermaid-3 .cluster text%7bfill:%23333%3b%7d%23mermaid-3 .cluster span%7bcolor:%23333%3b%7d%23mermaid-3 div.mermaidTooltip%7bposition:absolute%3btext-align:center%3bmax-width:200px%3bpadding:2px%3bfont-family:arial%2csans-serif%3bfont-size:12px%3bbackground:hsl(80%2c 100%25%2c 96.2745098039%25)%3bborder:1px solid %23aaaa33%3bborder-radius:2px%3bpointer-events:none%3bz-index:100%3b%7d%23mermaid-3 .flowchartTitleText%7btext-anchor:middle%3bfont-size:18px%3bfill:%23333%3b%7d%23mermaid-3 rect.text%7bfill:none%3bstroke-width:0%3b%7d%23mermaid-3 .icon-shape%2c%23mermaid-3 .image-shape%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3btext-align:center%3b%7d%23mermaid-3 .icon-shape p%2c%23mermaid-3 .image-shape p%7bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bpadding:2px%3b%7d%23mermaid-3 .icon-shape rect%2c%23mermaid-3 .image-shape rect%7bopacity:0.5%3bbackground-color:rgba(232%2c232%2c232%2c 0.8)%3bfill:rgba(232%2c232%2c232%2c 0.8)%3b%7d%23mermaid-3 .label-icon%7bdisplay:inline-block%3bheight:1em%3boverflow:visible%3bvertical-align:-0.125em%3b%7d%23mermaid-3 .node .label-icon path%7bfill:currentColor%3bstroke:revert%3bstroke-width:revert%3b%7d%23mermaid-3 :root%7b--mermaid-font-family:arial%2csans-serif%3b%7d%3c/style%3e%3cg%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-3_flowchart-v2-pointEnd'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 0 L 10 5 L 0 10 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='8' markerWidth='8' markerUnits='userSpaceOnUse' refY='5' refX='4.5' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-3_flowchart-v2-pointStart'%3e%3cpath style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 0 5 L 10 10 L 10 0 z'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='11' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-3_flowchart-v2-circleEnd'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5' refX='-1' viewBox='0 0 10 10' class='marker flowchart-v2' id='mermaid-3_flowchart-v2-circleStart'%3e%3ccircle style='stroke-width: 1%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' r='5' cy='5' cx='5'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='12' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-3_flowchart-v2-crossEnd'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cmarker orient='auto' markerHeight='11' markerWidth='11' markerUnits='userSpaceOnUse' refY='5.2' refX='-1' viewBox='0 0 11 11' class='marker cross flowchart-v2' id='mermaid-3_flowchart-v2-crossStart'%3e%3cpath style='stroke-width: 2%3b stroke-dasharray: 1%2c 0%3b' class='arrowMarkerPath' d='M 1%2c1 l 9%2c9 M 10%2c1 l -9%2c9'/%3e%3c/marker%3e%3cg class='root'%3e%3cg class='clusters'/%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_query_LLM_0' d='M123.375%2c449.276L123.375%2c454.468C123.375%2c459.66%2c123.375%2c470.044%2c160.675%2c482.396C197.974%2c494.748%2c272.573%2c509.068%2c309.873%2c516.228L347.173%2c523.388'/%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_LLM_agent_git_0' d='M373.75%2c551.553L373.75%2c559.719C373.75%2c567.886%2c373.75%2c584.219%2c415.507%2c611.515C457.264%2c638.811%2c540.779%2c677.07%2c582.536%2c696.199L624.293%2c715.328'/%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_git_LLM_0' d='M839.93%2c649.553L845.56%2c641.386C851.19%2c633.219%2c862.451%2c616.886%2c789.258%2c597.358C716.064%2c577.83%2c558.418%2c555.108%2c479.595%2c543.746L400.772%2c532.385'/%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_LLM_agent_github_0' d='M396.813%2c523.034L426.829%2c515.933C456.846%2c508.832%2c516.88%2c494.63%2c546.897%2c477.087C576.914%2c459.544%2c576.914%2c438.66%2c576.914%2c413.776C576.914%2c388.893%2c576.914%2c360.009%2c576.914%2c338.067C576.914%2c316.125%2c576.914%2c301.125%2c576.914%2c293.625L576.914%2c286.125'/%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_github_LLM_0' d='M427.254%2c282.125L418.336%2c290.292C409.419%2c298.458%2c391.585%2c314.792%2c382.667%2c337.4C373.75%2c360.009%2c373.75%2c388.893%2c373.75%2c413.776C373.75%2c438.66%2c373.75%2c459.544%2c373.75%2c473.486C373.75%2c487.428%2c373.75%2c494.428%2c373.75%2c497.928L373.75%2c501.428'/%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_memory_agent_git_0' d='M753.711%2c455.428L753.711%2c459.594C753.711%2c463.761%2c753.711%2c472.094%2c753.711%2c484.272C753.711%2c496.449%2c753.711%2c512.469%2c753.711%2c532.49C753.711%2c552.511%2c753.711%2c576.532%2c753.711%2c596.042C753.711%2c615.553%2c753.711%2c630.553%2c753.711%2c638.053L753.711%2c645.553'/%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_github_memory_0' d='M707.151%2c282.125L714.911%2c290.292C722.671%2c298.458%2c738.191%2c314.792%2c745.951%2c330.458C753.711%2c346.125%2c753.711%2c361.125%2c753.711%2c368.625L753.711%2c376.125'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(373.75%2c 600.5528106689453)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3eget changes in current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(873.7109375%2c 600.5528106689453)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3ediff %2bmain.ts -main.ts...%2b new code%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(576.9140625%2c 417.77640533447266)' class='edgeLabel'%3e%3cg transform='translate(-83.1640625%2c -12)' class='label'%3e%3cforeignObject height='24' width='166.328125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3equery the last failed run%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(373.75%2c 417.77640533447266)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -36)' class='label'%3e%3cforeignObject height='72' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3ecommit failed_sha is responsible%5cnsuccess_sha is last known good%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(753.7109375%2c 528.4903106689453)' class='edgeLabel'%3e%3cg transform='translate(-36.4765625%2c -12)' class='label'%3e%3cforeignObject height='24' width='72.953125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3efailed_sha%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(753.7109375%2c 331.125)' class='edgeLabel'%3e%3cg transform='translate(-100%2c -24)' class='label'%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3cp%3eremember failed_run%2c failed_sha%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(403.9140625%2c 0)' class='root'%3e%3cg class='clusters'%3e%3cg data-look='classic' id='agent_github' class='cluster'%3e%3crect height='274.125' width='330' y='8' x='8' style=''/%3e%3cg transform='translate(128.9609375%2c 8)' class='cluster-label'%3e%3cforeignObject height='24' width='88.078125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eagent github%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' marker-start='url(%23mermaid-3_flowchart-v2-pointStart)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_github_LLM_github_tools_0' d='M173%2c95.625L173%2c101.208C173%2c106.792%2c173%2c117.958%2c173%2c129.125C173%2c140.292%2c173%2c151.458%2c173%2c157.042L173%2c162.625'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(173%2c 68.5625)' id='flowchart-agent_github_LLM-12' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(173%2c 205.625)' id='flowchart-github_tools-13' class='node default'%3e%3crect height='78' width='260' y='-39' x='-130' style='' class='basic label-container'/%3e%3cg transform='translate(-100%2c -24)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3elist workflow runs%2c list jobs%2c diff job logs%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg transform='translate(619.9296875%2c 641.5528106689453)' class='root'%3e%3cg class='clusters'%3e%3cg data-look='classic' id='agent_git' class='cluster'%3e%3crect height='250.125' width='251.5625' y='8' x='8' style=''/%3e%3cg transform='translate(103.0859375%2c 8)' class='cluster-label'%3e%3cforeignObject height='24' width='61.390625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eagent git%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='edgePaths'%3e%3cpath marker-end='url(%23mermaid-3_flowchart-v2-pointEnd)' marker-start='url(%23mermaid-3_flowchart-v2-pointStart)' style='' class='edge-thickness-normal edge-pattern-solid edge-thickness-normal edge-pattern-solid flowchart-link' id='L_agent_git_LLM_git_tools_0' d='M133.781%2c95.625L133.781%2c101.208C133.781%2c106.792%2c133.781%2c117.958%2c133.781%2c129.125C133.781%2c140.292%2c133.781%2c151.458%2c133.781%2c157.042L133.781%2c162.625'/%3e%3c/g%3e%3cg class='edgeLabels'%3e%3cg class='edgeLabel'%3e%3cg transform='translate(0%2c 0)' class='label'%3e%3cforeignObject height='0' width='0'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' class='labelBkg' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='edgeLabel'%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg class='nodes'%3e%3cg transform='translate(133.78125%2c 68.5625)' id='flowchart-agent_git_LLM-6' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(133.78125%2c 193.625)' id='flowchart-git_tools-7' class='node default'%3e%3crect height='54' width='181.5625' y='-27' x='-90.78125' style='' class='basic label-container'/%3e%3cg transform='translate(-60.78125%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='121.5625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3egit branch%2c git diff%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3cg transform='translate(123.375%2c 417.77640533447266)' id='flowchart-query-0' class='node default'%3e%3crect height='63' width='230.75' y='-31.5' x='-115.375' ry='31.5' rx='31.5' style='' class='basic label-container'/%3e%3cg transform='translate(-100%2c -24)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='48' width='200'%3e%3cdiv style='display: table%3b white-space: break-spaces%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b width: 200px%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3esummarize changes in the current branch%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(373.75%2c 528.4903106689453)' id='flowchart-LLM-1' class='node default'%3e%3ccircle cy='0' cx='0' r='23.0625' style='' class='basic label-container'/%3e%3cg transform='translate(-15.5625%2c -12)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='31.125'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eLLM%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3cg transform='translate(753.7109375%2c 417.77640533447266)' id='flowchart-memory-14' class='node default'%3e%3cpath transform='translate(-58.6328125%2c -37.65140277329894)' style='' class='basic label-container' d='M0%2c12.10093518219929 a58.6328125%2c12.10093518219929 0%2c0%2c0 117.265625%2c0 a58.6328125%2c12.10093518219929 0%2c0%2c0 -117.265625%2c0 l0%2c51.100935182199294 a58.6328125%2c12.10093518219929 0%2c0%2c0 117.265625%2c0 l0%2c-51.100935182199294'/%3e%3cg transform='translate(-51.1328125%2c -2)' style='' class='label'%3e%3crect/%3e%3cforeignObject height='24' width='102.265625'%3e%3cdiv style='display: table-cell%3b white-space: nowrap%3b line-height: 1.5%3b max-width: 200px%3b text-align: center%3b' xmlns='http://www.w3.org/1999/xhtml'%3e%3cspan class='nodeLabel'%3e%3cp%3eagent memory%3c/p%3e%3c/span%3e%3c/div%3e%3c/foreignObject%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e>)

All agents contribute to the conversation memory unless it is explicitly disabled using `disableMemory`.

```js
defAgent(..., { disableMemory: true })
```

## defAgent

[Section titled “defAgent”](#defagent)

The `defAgent` function is used to define an agent that can be called by the LLM. It takes a JSON schema to define the input and expects a string output. The LLM autonomously decides to call this agent.

```ts
defAgent(
    "git", // agent id becomes 'agent_git'
    "Handles any git operation", // description
    "You are a helpful expert in using git.",
    {
        tools: ["git"],
    }
)
```

* the agent id will become the tool id `agent_<id>`
* the description of the agent will automatically be augmented with information about the available tools

## Multiple instances of the same agent

[Section titled “Multiple instances of the same agent”](#multiple-instances-of-the-same-agent)

Some agents, like `agent_git`, can be instantiated with different configurations, like working on different repositories.

multi-agents.genai.mts

```js
script({
  system: [
    "system.agent_git",
    {
      id: "system.agent_git",
      parameters: { repo: "microsoft/jacdac", variant: "jacdac" },
    },
  ],
});


$`Generate a table with the last commits of the jacdac and current git repository?`;
```

### Builtin Agents

[agent data ](/genaiscript/reference/scripts/system#systemagent_data)query data from files

[agent docs ](/genaiscript/reference/scripts/system#systemagent_docs)query the documentation

[agent fs ](/genaiscript/reference/scripts/system#systemagent_fs)query files to accomplish tasks

[agent git ](/genaiscript/reference/scripts/system#systemagent_git)query the current repository using Git to accomplish tasks. Provide all the context information available to execute git queries.

[agent github ](/genaiscript/reference/scripts/system#systemagent_github)query GitHub to accomplish tasks

[agent interpreter ](/genaiscript/reference/scripts/system#systemagent_interpreter)run code interpreters for Python, Math. Use this agent to ground computation questions.

[agent planner ](/genaiscript/reference/scripts/system#systemagent_planner)generates a plan to solve a task

[agent user\_input ](/genaiscript/reference/scripts/system#systemagent_user_input)ask user for input to confirm, select or answer the question in the query. The message should be very clear and provide all the context.

[agent video ](/genaiscript/reference/scripts/system#systemagent_video)Analyze and process video files or urls.

[agent web ](/genaiscript/reference/scripts/system#systemagent_web)search the web to accomplish tasks.

[agent z3 ](/genaiscript/reference/scripts/system#systemagent_z3)can formalize and solve problems using the Z3 constraint solver. If you need to run Z3 or solve constraint systems, use this tool.

## Example `agent_github`

[Section titled “Example agent\_github”](#example-agent_github)

Let’s illustrate this by building a GitHub agent. The agent is a tool that receives a query and executes an LLM prompt with GitHub-related tools.

The definition of the agent looks like this:

```js
defAgent(
    "github", // id
    "query GitHub to accomplish tasks", // description
    // callback to inject content in the LLM agent prompt
    (ctx) =>
        ctx.$`You are a helpful LLM agent that can query GitHub to accomplish tasks.`,
    {
        // list tools that the agent can use
        tools: ["github_actions"],
    }
)
```

and internally it is expanded to the following:

```js
defTool(
    // agent_ is always prefixed to the agent id
    "agent_github",
    // the description is augmented with the tool descriptions
    `Agent that can query GitHub to accomplish tasks


    Capabilities:
    - list github workflows
    - list github workflows runs
    ...`,
    // all agents have a single "query" parameter
    {
        query: {
            type: "string",
            description: "Query to answer",
        },
        required: ["query"]
    },
    async(args) => {
        const { query } = args
        ...
    })
```

Inside callback, we use `runPrompt` to run an LLM query.

* the prompt takes the query argument and tells the LLM how to handle it.
* note the use of `ctx.` for nested prompts

```js
        const res = await runPrompt(
            (ctx) => {
                // callback to inject content in the LLM agent prompt
                ctx.$`You are a helpful LLM agent that can query GitHub to accomplish tasks.`


                ctx.def("QUERY", query)
                _.$`Analyze and answer QUERY.
                - Assume that your answer will be analyzed by an LLM, not a human.
                - If you cannot answer the query, return an empty string.
                `
            }, , {
                system: [...],
                // list of tools that the agent can use
                tools: ["github_actions", ...]
            }
        )
        return res
```

## Selecting the Tools and System Prompts

[Section titled “Selecting the Tools and System Prompts”](#selecting-the-tools-and-system-prompts)

We use the `system` parameter to configure the tools exposed to the LLM. In this case, we expose the GitHub tools (`system.github_files`, `system.github_issues`, …)

```js
            {
                system: [
                    "system",
                    "system.tools",
                    "system.explanations",
                    "system.github_actions",
                    "system.github_files",
                    "system.github_issues",
                    "system.github_pulls",
                ],
            }
```

This full source of this agent is defined in the [system.agent\_github](/genaiscript/reference/scripts/system/#systemagent_github) system prompt.

## Logging

[Section titled “Logging”](#logging)

Each agent uses a `agent:<name>` [logging](/genaiscript/reference/scripts/logging) namespace to report debugging information.

To get logging from the cli, you can use the `DEBUG` environment variable to enable logging for a specific agent.

```sh
DEBUG=agent:github* genaiscript run ...
```