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

# Agent SDK

> Programmable interface for text chat, conversation memory, and document Q&A (RAG)

<Info>
  **Source Code:** [`src/gaia/chat/sdk.py`](https://github.com/amd/gaia/blob/main/src/gaia/chat/sdk.py) · [`src/gaia/rag/sdk.py`](https://github.com/amd/gaia/blob/main/src/gaia/rag/sdk.py)
</Info>

<Note>
  **Import:** `from gaia.chat.sdk import AgentSDK, AgentConfig, SimpleChat, AgentSession, quick_chat`
</Note>

**See also:** [User Guide](/docs/guides/chat) · [API Specification](/docs/spec/agent-sdk)

***

## Core Classes

### AgentConfig

Configure your chat session:

```python theme={null}
@dataclass
class AgentConfig:
    model: str = "Gemma-4-E4B-it-GGUF"  # Default validated model (DEFAULT_MODEL_NAME)
    max_tokens: int = 512
    temperature: Optional[float] = None
    system_prompt: Optional[str] = None
    max_history_length: int = 4
    show_stats: bool = False
    logging_level: str = "INFO"
    use_claude: bool = False       # Use Claude API
    use_chatgpt: bool = False      # Use ChatGPT/OpenAI API
    use_local_llm: bool = True     # Use local LLM
    claude_model: str = "claude-sonnet-4-20250514"
    base_url: Optional[str] = None # Lemonade server URL
    assistant_name: str = "gaia"
```

### AgentResponse

Responses include text, history, and optional statistics:

```python theme={null}
@dataclass
class AgentResponse:
    text: str
    history: Optional[List[str]] = None
    stats: Optional[Dict[str, Any]] = None
    is_complete: bool = True  # False for streaming chunks
```

### SimpleChat

Lightweight wrapper for basic chat without complex configuration. Perfect for getting started quickly.

```python theme={null}
from gaia.chat.sdk import SimpleChat

chat = SimpleChat()
response = chat.ask("What is Python?")
print(response)

# Follow-up with conversation memory
response = chat.ask("Give me an example")
print(response)
```

***

## Quick Chat (One-Off)

```python theme={null}
from gaia.chat.sdk import quick_chat

# Single query — returns str directly
response = quick_chat("What is machine learning?")
print(response)

# With options
response = quick_chat(
    "Explain quantum computing",
    model="Qwen3.5-35B-A3B-GGUF",
    system_prompt="You are a physics teacher."
)
print(response)
```

***

## Chat with Memory

```python theme={null}
from gaia.chat.sdk import AgentSDK, AgentConfig

config = AgentConfig(
    model="Qwen3-0.6B-GGUF",
    max_tokens=512,
    max_history_length=4,
    system_prompt="You are a helpful coding assistant.",
    assistant_name="CodeBot"
)

chat = AgentSDK(config)

# Multi-turn conversation
response1 = chat.send("What is Python?")
print(response1.text)

response2 = chat.send("Show me an example")
print(response2.text)  # LLM remembers context

# Check history
history = chat.get_history()
print(f"Conversation turns: {len(history)}")

chat.clear_history()
```

***

## Streaming

```python theme={null}
from gaia.chat.sdk import AgentSDK

chat = AgentSDK()

print("AI: ", end="", flush=True)
for chunk in chat.send_stream("Tell me a story"):
    if not chunk.is_complete:
        print(chunk.text, end="", flush=True)
print()
```

***

## Custom Assistant

```python theme={null}
from gaia.chat.sdk import AgentConfig, AgentSDK

config = AgentConfig(
    assistant_name="Gaia",
    system_prompt="You are Gaia, a helpful AI assistant."
)
chat = AgentSDK(config)

response = chat.send("What's your name?")
print(f"Gaia: {response.text}")
```

***

## Session Management

Manage multiple conversation contexts:

```python theme={null}
from gaia.chat.sdk import AgentSession

sessions = AgentSession()

# Create different contexts with custom names
work_chat = sessions.create_session(
    "work",
    system_prompt="You are a professional assistant.",
    assistant_name="WorkBot"
)

personal_chat = sessions.create_session(
    "personal",
    system_prompt="You are a friendly companion.",
    assistant_name="Buddy"
)

# Separate conversation histories
work_response = work_chat.send("Draft a team email")
personal_response = personal_chat.send("What's for dinner?")
```

***

## Conversation History

```python theme={null}
from gaia.chat.sdk import AgentSDK

chat = AgentSDK()

chat.send("Hello")
chat.send("How are you?")

# Get formatted history
for entry in chat.get_formatted_history():
    print(f"{entry['role']}: {entry['message']}")

chat.clear_history()
print(f"Conversation pairs: {chat.conversation_pairs}")
```

***

## Chat with RAG

```python theme={null}
from gaia.chat.sdk import AgentSDK

chat = AgentSDK()

# Enable RAG and index documents
chat.enable_rag(documents=["manual.pdf", "guide.pdf"])

# Chat with document context
response = chat.send("What does the manual say about installation?")
print(response.text)

# Add more documents
chat.add_document("troubleshooting.pdf")

# Disable RAG when done
chat.disable_rag()
```

### Advanced RAG Configuration

```python theme={null}
from gaia.chat.sdk import AgentSDK

chat = AgentSDK()

chat.enable_rag(
    documents=["doc1.pdf", "doc2.pdf"],
    chunk_size=600,      # Larger chunks for more context
    max_chunks=4,        # More chunks per query
    chunk_overlap=100    # Overlap for context preservation
)

if chat.rag:
    status = chat.rag.get_status()
    print(f"Indexed {status['indexed_files']} files")
    print(f"Total chunks: {status['total_chunks']}")
```

***

## Custom Messages

```python theme={null}
from gaia.chat.sdk import AgentSDK

chat = AgentSDK()

messages = [
    {"role": "system", "content": "You are a math tutor."},
    {"role": "user", "content": "Explain calculus"},
    {"role": "assistant", "content": "Calculus is..."},
    {"role": "user", "content": "Give me an example"}
]

response = chat.send_messages(
    messages=messages,
    system_prompt="Be concise and clear"
)
print(response.text)
```

***

## API Reference

### AgentSDK Methods

<CardGroup cols={2}>
  <Card title="Messaging" icon="message">
    * `send(message: str) -> AgentResponse`
    * `send_stream(message: str)`
    * `send_messages(messages, system_prompt) -> AgentResponse`
  </Card>

  <Card title="History" icon="clock-rotate-left">
    * `get_history() -> List[str]`
    * `clear_history()`
    * `get_formatted_history() -> List[Dict]`
    * `conversation_pairs` (property)
  </Card>

  <Card title="RAG (Document Q&A)" icon="book">
    * `enable_rag(documents=None, **kwargs)`
    * `disable_rag()`
    * `add_document(path: str) -> bool`
  </Card>

  <Card title="Configuration" icon="gear">
    * `update_config(**kwargs)`
    * `get_stats() -> Dict`
    * `display_stats(stats=None)`
    * `start_interactive_session()`
  </Card>
</CardGroup>

### SimpleChat Methods

* `ask(question: str) -> str` — Ask question, get response
* `ask_stream(question: str)` — Ask question, stream response
* `clear_memory()` — Clear conversation memory
* `get_conversation() -> List[Dict]` — Get conversation history

### AgentSession Methods

* `create_session(session_id, config=None, **kwargs) -> AgentSDK` — Create new session
* `get_session(session_id) -> AgentSDK` — Get existing session
* `delete_session(session_id) -> bool` — Delete session
* `list_sessions() -> List[str]` — List all sessions
* `clear_all_sessions()` — Delete all sessions

### Utility Functions

* `quick_chat(message, system_prompt=None, model=None, assistant_name=None) -> str`
* `quick_chat_with_memory(messages, system_prompt=None, model=None, assistant_name=None) -> List[str]`

***

## Best Practices

<CardGroup cols={2}>
  <Card title="Choose the Right Interface" icon="code-branch">
    `SimpleChat` for basic needs, `AgentSDK` for full features, `AgentSession` for multi-context apps
  </Card>

  <Card title="Memory Management" icon="memory">
    Configure `max_history_length` based on memory constraints
  </Card>

  <Card title="Performance" icon="chart-line">
    Enable `show_stats=True` during development
  </Card>

  <Card title="Resource Cleanup" icon="broom">
    Clear sessions when done to free memory
  </Card>
</CardGroup>

***

## Related

* **[User Guide](/docs/guides/chat)** — CLI usage, RAG commands, troubleshooting
* **[GAIA Chat Desktop](/docs/guides/agent-ui)** — Desktop app with GUI and document Q\&A
* **[Agent UI SDK](./agent-ui)** — Python backend for the desktop application (FastAPI, SQLite, REST API)
* **[LLM Client](./llm)** — Language model integration
* **[API Specification](/docs/spec/agent-sdk)** — Technical specification

***

<small style="color: #666;">
  Copyright(C) 2024-2026 Advanced Micro Devices, Inc. All rights reserved.

  SPDX-License-Identifier: MIT
</small>
