> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-ai/boxlang-ai/agents.md).

# Agents

Build AI agents with instructions, tools, memory, skills, and MCP servers, and control runs in flight.

An **agent** is a model plus instructions, and optionally memory, tools, skills, and MCP servers. It decides when to use them to complete a task.

## 🚀 Your First Agent

```js
agent = aiAgent(
    name: "Assistant",
    description: "A helpful AI assistant",
    instructions: "Be concise and friendly"
)

response = agent.run( "What is BoxLang?" )
println( response )
```

## 🧰 Give It Capabilities

**Tools** let the agent call your code:

```js
weatherTool = aiTool(
    "get_weather",
    "Get current weather for a location",
    location => getWeatherData( location )
).describeLocation( "City and country, e.g. Boston, MA" )

agent = aiAgent(
    name: "TaskAgent",
    instructions: "Use tools when needed. Be precise and helpful.",
    tools: [ weatherTool ]
)

agent.run( "What's the weather in Boston?" )
```

**Web search** for current information:

```js
agent = aiAgent(
    name: "ResearchAssistant",
    instructions: "Use web search for current information and cite your sources.",
    tools: [ "webSearch@bxai" ]
)
```

**Skills** inject domain knowledge into the agent's context:

```js
agent = aiAgent(
    name: "CodeReviewer",
    instructions: "Review code for quality and security",
    skills: aiSkill( ".ai/skills/security" ),
    availableSkills: aiSkill( ".ai/skills/languages" )
)
```

**MCP servers** provide tools from anywhere:

```js
agent = aiAgent(
    name: "ResearchAgent",
    mcpServers: [
        {
            url: "http://localhost:3000/mcp",
            toolNames: [ "web_search", "fetch_page" ]
        }
    ]
)
```

## 🧠 Agents That Remember

Give an agent memory and it keeps context across turns. See [Memory & RAG](/boxlang-ai/boxlang-ai/memory-and-rag.md).

## 🏗️ More Patterns

* **Class-based agents** for reusable, testable agents
* **Sub-agents and hierarchies** where a coordinator delegates to specialists
* **Streaming** agent responses
* **Run control** to cancel or steer a run that is already in flight
* **Middleware** to add logging, retries, guardrails, and approvals without changing agent logic. See [Governance & Security](/boxlang-ai/boxlang-ai/governance-and-security.md).

## 🔍 Go Deeper

* [Agents overview](https://ai.ortusbooks.com/main-components/agents)
* [Getting Started with Agents](https://ai.ortusbooks.com/main-components/agents/getting-started)
* [Class-Based Agents](https://ai.ortusbooks.com/main-components/agents/class-based-agents)
* [Memory Management](https://ai.ortusbooks.com/main-components/agents/memory)
* [Sub-Agents & Hierarchy](https://ai.ortusbooks.com/main-components/agents/hierarchy)
* [Run Control](https://ai.ortusbooks.com/main-components/agents/run-control)
* [Advanced Patterns](https://ai.ortusbooks.com/main-components/agents/advanced)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-ai/boxlang-ai/agents.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
