> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bindai.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 02.2 prompts

# Prompts

Prompts define how an AI agent behaves.

In BindAI, prompts are treated as reusable, structured objects instead of raw strings.

They can be:

* stored in Python
* loaded from YAML
* reused across agents
* parameterized with variables
* composed dynamically

***

# What is a Prompt?

A prompt contains the instructions sent to the language model before generation.

The most common prompt is the **system prompt**, which defines the agent's behavior.

Example:

```text id="m4v9s2" theme={null}
You are an experienced software architect.

Always explain your reasoning clearly.

Keep answers concise.
```

***

# Prompt Object

BindAI provides a dedicated `Prompt` object.

```python id="y7hx3k" theme={null}
from bindai_prompts import Prompt

prompt = Prompt()

prompt.system = (
    "You are a helpful assistant."
)
```

Agents automatically use the prompt during execution.

***

# Creating an Agent

```python id="v1s4nb" theme={null}
from bindai_agent import Agent
from bindai_openai import OpenAIProvider
from bindai_prompts import Prompt

prompt = Prompt()

prompt.system = (
    "You are a helpful assistant."
)

agent = Agent(
    name="assistant",
    provider=OpenAIProvider.from_env(),
    prompt=prompt,
)
```

***

# Using Instructions

The simplest way to create a prompt is by using the `instructions` parameter.

```python id="f8kq6j" theme={null}
agent = Agent(
    name="assistant",
    provider=provider,
    instructions="""
You are a helpful assistant.

Answer in one sentence.
""",
)
```

Internally, BindAI stores these instructions inside the prompt object.

***

# YAML Prompts

Prompts are commonly stored in YAML.

```yaml id="s3jp1n" theme={null}
name: assistant

model: openai:gpt-4.1-mini

instructions: |
  You are a helpful assistant.

  Keep answers concise.
```

Loading the agent automatically loads the prompt.

```python id="t6r2wc" theme={null}
agent = Agent.from_yaml(
    "assistant.yaml"
)
```

Keeping prompts in YAML makes them easier to maintain and update without changing Python code.

***

# Variables

Prompts often contain dynamic values.

Example:

```text id="d5kw8v" theme={null}
Summarize the following document:

{{document}}
```

The application replaces variables before execution.

Example:

```python id="h4pw7x" theme={null}
document = "Large document..."

message = f"""
Summarize:

{document}
"""

agent.chat(message)
```

***

# Static vs Dynamic Prompts

Static prompt:

```text id="g8ms2e" theme={null}
You are a financial advisor.
```

Dynamic prompt:

```text id="o9xc5d" theme={null}
You are a financial advisor.

Today's market:

{{market_data}}
```

Dynamic prompts allow the application to inject runtime information.

***

# Prompt Composition

Prompts can be built from multiple sections.

Example:

```text id="u2nb6a" theme={null}
Role

Goals

Constraints

Output format
```

Instead of writing one large prompt, separate responsibilities into logical sections.

***

# Output Instructions

Prompts often define how responses should be formatted.

Example:

```text id="r3yt7h" theme={null}
Respond using Markdown.

Return only bullet points.
```

Or:

```text id="c8ln4k" theme={null}
Respond with valid JSON.
```

These instructions help produce predictable outputs.

***

# Prompt Reuse

A single prompt can be shared across multiple agents.

```python id="z6jh8m" theme={null}
prompt = Prompt()

prompt.system = (
    "You are a technical writer."
)

writer = Agent(
    name="writer",
    provider=provider,
    prompt=prompt,
)

editor = Agent(
    name="editor",
    provider=provider,
    prompt=prompt,
)
```

This keeps behavior consistent throughout a project.

***

# Prompts and Memory

Prompts define behavior.

Memory provides context.

Together they determine how an agent responds.

```text id="w1bn5v" theme={null}
Prompt

      +

Memory

      +

Conversation

      =

Model Request
```

Each serves a different purpose.

***

# Prompts and Knowledge

Knowledge retrieval occurs before model generation.

Retrieved information becomes additional context, while the prompt continues to define the agent's role and instructions.

The prompt should describe **how** to use retrieved information, not contain the information itself.

***

# Best Practices

* Keep prompts focused on one responsibility.
* Store prompts in YAML when possible.
* Keep instructions concise.
* Separate behavior from runtime data.
* Use variables instead of duplicating prompts.
* Clearly define the expected output format.
* Reuse prompts across similar agents.
