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

# Single Agent

> Learn how to create a basic single-purpose AI agent for simple tasks.

The simplest possible Agent — one instruction, no tools, one call. This is the plain `Agent` showcase.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="ContentWriter",
    instructions="You are a content writer. Output in markdown format.",
)

agent.start("Write a short blog post about AI assistants")
```

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Single Agent"
        User[📋 Input] --> Agent[🤖 Agent]
        Agent --> LLM[🧠 LLM]
        LLM --> Result[✅ Output]
    end

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent input
    class LLM process
    class Result output
```

Single-purpose agent for content generation. Minimal setup, no external tools.

## Quick Start

<Steps>
  <Step title="Simple Usage">
    Create an agent with one instruction and call it.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(
        name="ContentWriter",
        instructions="You are a content writer. Output in markdown format.",
    )

    agent.start("Write a short blog post about AI assistants")
    ```
  </Step>

  <Step title="With Configuration">
    Add memory and structured output for richer behaviour.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, Task, AgentTeam
    from pydantic import BaseModel

    class BlogPost(BaseModel):
        title: str
        content: str
        tags: list[str]

    agent = Agent(
        name="ContentWriter",
        instructions="Write structured blog posts.",
        memory=True,
    )

    task = Task(
        description="Write a short blog post about AI assistants",
        expected_output="Structured blog post",
        agent=agent,
        output_pydantic=BlogPost,
    )

    AgentTeam(agents=[agent], tasks=[task]).start()
    ```
  </Step>
</Steps>

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant LLM

    User->>Agent: "Write a blog post about AI"
    Agent->>LLM: Send instructions + prompt
    LLM-->>Agent: Generated content
    Agent-->>User: Final response
```

***

## Simple

**Agents: 1** — Single task requires only one agent.

### Workflow

1. Receive input prompt
2. Process with LLM
3. Return generated content

### Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonaiagents praisonai
export OPENAI_API_KEY="your-key"
```

### Run — Python

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="ContentWriter",
    instructions="You are a content writer. Output in markdown format."
)

result = agent.start("Write a short blog post about AI assistants")
print(result)
```

### Run — CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "Write a short blog post about AI assistants"
```

### Run — agents.yaml

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
framework: praisonai
topic: Content Generation
roles:
  content_writer:
    role: Content Writer
    goal: Generate engaging content
    backstory: You are an expert content writer
    tasks:
      write_content:
        description: Write a short blog post about AI assistants
        expected_output: A markdown formatted blog post
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai agents.yaml
```

### Serve API

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="ContentWriter",
    instructions="You are a content writer. Output in markdown format."
)

agent.launch(port=8080)
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Write a haiku about coding"}'
```

***

## Advanced Workflow (All Features)

**Agents: 1** — Single agent with memory, persistence, structured output, and session resumability.

### Workflow

1. Initialize session with unique ID for resumability
2. Configure SQLite persistence for conversation history
3. Process input with structured Pydantic output
4. Store results in memory for future context
5. Resume session later with same session\_id

### Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonaiagents praisonai pydantic
export OPENAI_API_KEY="your-key"
```

### Run — Python

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Task, AgentTeam, Session
from pydantic import BaseModel

# Structured output schema
class BlogPost(BaseModel):
    title: str
    content: str
    tags: list[str]

# Create session for resumability
session = Session(session_id="blog-session-001", user_id="user-1")

# Agent with memory enabled
agent = Agent(
    name="ContentWriter",
    instructions="You are a content writer. Output structured JSON.",
    memory=True
)

# Task with structured output
task = Task(
    description="Write a short blog post about AI assistants",
    expected_output="Structured blog post",
    agent=agent,
    output_pydantic=BlogPost
)

# Run with SQLite persistence
agents = AgentTeam(
    agents=[agent],
    tasks=[task],
    memory=True
)

result = agents.start()
print(result)

# Resume later with same session_id
session2 = Session(session_id="blog-session-001", user_id="user-1")
context = session2.get_context()
```

### Run — CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# With memory and verbose
praisonai "Write a blog post about AI" --memory --verbose

# With session persistence
praisonai "Continue the blog post" --memory --session blog-session-001
```

### Run — agents.yaml

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
framework: praisonai
topic: Content Generation
memory: true
memory_config:
  provider: sqlite
  db_path: content.db
roles:
  content_writer:
    role: Content Writer
    goal: Generate engaging content with structured output
    backstory: You are an expert content writer
    memory: true
    tasks:
      write_content:
        description: Write a short blog post about AI assistants
        expected_output: Structured blog post with title, content, and tags
        output_json:
          title: string
          content: string
          tags: array
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai agents.yaml --verbose
```

### Serve API

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="ContentWriter",
    instructions="You are a content writer.",
    memory=True
)

# Launch with persistence
agent.launch(port=8080)
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Write a blog post", "session_id": "blog-001"}'
```

***

## Save Output to File

Save agent responses to files using different methods:

<Tabs>
  <Tab title="write_file Tool">
    Agent decides when to save:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent
    from praisonaiagents.tools import write_file

    agent = Agent(
        name="Writer",
        instructions="Write content and save to files",
        tools=[write_file]
    )
    agent.start("Write a poem and save it to poem.txt")
    ```
  </Tab>

  <Tab title="Task output_file">
    Auto-save task result:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, Task, AgentTeam

    agent = Agent(name="Writer")
    task = Task(
        description="Write a poem",
        agent=agent,
        output_file="poem.txt",
        create_directory=True
    )
    agents = AgentTeam(agents=[agent], tasks=[task])
    agents.start()
    ```
  </Tab>

  <Tab title="Manual">
    Full control:

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    agent = Agent(name="Writer")
    response = agent.start("Write a poem")
    with open("poem.txt", "w") as f:
        f.write(response)
    ```
  </Tab>
</Tabs>

<Tip>
  See [Save Agent Output](/features/save-output) for complete guide.
</Tip>

***

## Monitor / Verify

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Verbose output
praisonai "test prompt" --verbose

# Check telemetry
praisonai "test prompt" --telemetry
```

## Cleanup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
rm -f content.db
```

## Features Demonstrated

| Feature           | Implementation                 |
| ----------------- | ------------------------------ |
| Workflow          | Single-step content generation |
| DB Persistence    | SQLite via `memory_config`     |
| Observability     | `--verbose` flag               |
| Resumability      | `Session` with `session_id`    |
| Structured Output | Pydantic `BlogPost` model      |

## Best Practices

<AccordionGroup>
  <Accordion title="Start here before reaching for tools">
    A plain Agent handles most text tasks. Add tools only when the job genuinely needs live data or actions the model cannot perform alone.
  </Accordion>

  <Accordion title="Keep instructions specific">
    The single instruction shapes every response. A precise role — "content writer, output Markdown" — beats a vague "be helpful" for consistent results.
  </Accordion>

  <Accordion title="Add memory for multi-turn work">
    Set `memory=True` when a task spans several messages so the agent keeps context instead of treating each call as new.
  </Accordion>

  <Accordion title="Save output when generating at scale">
    Use a Task with `output_file` or a file-writing tool so generated content lands on disk automatically.
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card icon="globe" href="/docs/agents/websearch">
    Add a search tool for real-time information.
  </Card>

  <Card icon="link" href="/features/promptchaining">
    Chain prompts for multi-step workflows.
  </Card>
</CardGroup>
