> ## 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.

# Agent • AI Agent SDK

> Agent: Class reference for Agent

# Agent

> Defined in the [**agent**](../modules/agent) module.

<Badge color="blue">AI Agent</Badge>

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%

graph LR
    input["Input Data"] --> agent["Agent: Agent"]
    agent --> output["Output Result"]
    style agent fill:#8B0000,color:#fff
    style input fill:#8B0000,color:#fff
    style output fill:#8B0000,color:#fff
```

## Constructor

<ParamField query="name" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="role" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="goal" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="backstory" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="instructions" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="llm" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="model" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="base_url" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="api_key" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="auth" type="Optional[str]" required={false}>
  No description available.
</ParamField>

<ParamField query="tools" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="toolsets" type="Optional" required={false}>
  No description available.
</ParamField>

## Methods

<CardGroup cols={2}>
  <Card title="from_template()" icon="function" href="../functions/Agent-from_template">
    Create an Agent from a template.
  </Card>

  <Card title="stream_emitter()" icon="function" href="../functions/Agent-stream_emitter">
    Lazy-loaded StreamEventEmitter for real-time events (zero overhead when not used).
  </Card>

  <Card title="stream_emitter()" icon="function" href="../functions/Agent-stream_emitter">
    Allow setting stream\_emitter directly.
  </Card>

  <Card title="llm_instance()" icon="function" href="../functions/Agent-llm_instance">
    Instance method.
  </Card>

  <Card title="llm_instance()" icon="function" href="../functions/Agent-llm_instance">
    Instance method.
  </Card>

  <Card title="clone_for_channel()" icon="function" href="../functions/Agent-clone_for_channel">
    Return a fully independent copy of this agent for a gateway channel.
  </Card>

  <Card title="chat_history()" icon="function" href="../functions/Agent-chat_history">
    Get chat history (read-only access, use context managers for modifications).
  </Card>

  <Card title="chat_history()" icon="function" href="../functions/Agent-chat_history">
    Set chat history (updates the underlying async-safe state with lock).
  </Card>

  <Card title="auto_memory()" icon="function" href="../functions/Agent-auto_memory">
    AutoMemory instance for automatic memory extraction.
  </Card>

  <Card title="auto_memory()" icon="function" href="../functions/Agent-auto_memory">
    Instance method.
  </Card>

  <Card title="policy()" icon="function" href="../functions/Agent-policy">
    PolicyEngine instance for execution control.
  </Card>

  <Card title="policy()" icon="function" href="../functions/Agent-policy">
    Instance method.
  </Card>

  <Card title="output_style()" icon="function" href="../functions/Agent-output_style">
    OutputStyle instance for response formatting.
  </Card>

  <Card title="output_style()" icon="function" href="../functions/Agent-output_style">
    Instance method.
  </Card>

  <Card title="thinking_budget()" icon="function" href="../functions/Agent-thinking_budget">
    ThinkingBudget instance for extended thinking control.
  </Card>

  <Card title="thinking_budget()" icon="function" href="../functions/Agent-thinking_budget">
    Instance method.
  </Card>

  <Card title="reasoning_effort()" icon="function" href="../functions/Agent-reasoning_effort">
    Unified, provider-portable reasoning-effort level (Issue #4452).
  </Card>

  <Card title="reasoning_effort()" icon="function" href="../functions/Agent-reasoning_effort">
    Instance method.
  </Card>

  <Card title="total_cost()" icon="function" href="../functions/Agent-total_cost">
    Cumulative USD cost of all LLM calls in this agent run.
  </Card>

  <Card title="cost_summary()" icon="function" href="../functions/Agent-cost_summary">
    Summary of cost and token usage.
  </Card>

  <Card title="context_manager()" icon="function" href="../functions/Agent-context_manager">
    ContextManager instance for unified context management.
  </Card>

  <Card title="context_manager()" icon="function" href="../functions/Agent-context_manager">
    Set context manager directly.
  </Card>

  <Card title="console()" icon="function" href="../functions/Agent-console">
    Lazily initialize Rich Console only when needed AND verbose is True.
  </Card>

  <Card title="skill_manager()" icon="function" href="../functions/Agent-skill_manager">
    Lazily initialize SkillManager only when skills are accessed.
  </Card>

  <Card title="get_skills_prompt()" icon="function" href="../functions/Agent-get_skills_prompt">
    Get the XML prompt for available skills.
  </Card>

  <Card title="last_stop_reason()" icon="function" href="../functions/Agent-last_stop_reason">
    Structured reason the last tool-execution loop stopped.
  </Card>

  <Card title="agent_id()" icon="function" href="../functions/Agent-agent_id">
    Lazily generate agent ID when first accessed.
  </Card>

  <Card title="display_name()" icon="function" href="../functions/Agent-display_name">
    Safe display name that never returns None.
  </Card>

  <Card title="set_snapshot_root()" icon="function" href="../functions/Agent-set_snapshot_root">
    Root filesystem change-tracking at `project_path`.
  </Card>

  <Card title="undo()" icon="function" href="../functions/Agent-undo">
    Undo the last set of file changes.
  </Card>

  <Card title="redo()" icon="function" href="../functions/Agent-redo">
    Redo a previously undone set of file changes.
  </Card>

  <Card title="diff()" icon="function" href="../functions/Agent-diff">
    Get file diffs from autonomous execution.
  </Card>

  <Card title="analyze_prompt()" icon="function" href="../functions/Agent-analyze_prompt">
    Analyze prompt for autonomy signals.
  </Card>

  <Card title="get_recommended_stage()" icon="function" href="../functions/Agent-get_recommended_stage">
    Get recommended execution stage for prompt.
  </Card>

  <Card title="run_autonomous()" icon="function" href="../functions/Agent-run_autonomous">
    Run an autonomous task execution loop.
  </Card>

  <Card title="run_autonomous_async()" icon="function" href="../functions/Agent-run_autonomous_async">
    Async variant of run\_autonomous() for concurrent agent execution.
  </Card>

  <Card title="handoff_to()" icon="function" href="../functions/Agent-handoff_to">
    Programmatically hand off a task to another agent.
  </Card>

  <Card title="run_until()" icon="function" href="../functions/Agent-run_until">
    Run agent iteratively until output meets quality criteria.
  </Card>

  <Card title="run_until_async()" icon="function" href="../functions/Agent-run_until_async">
    Async version of run\_until().
  </Card>

  <Card title="handoff_to_async()" icon="function" href="../functions/Agent-handoff_to_async">
    Asynchronously hand off a task to another agent.
  </Card>

  <Card title="add_verification()" icon="function" href="../functions/Agent-add_verification">
    Register a verification hook for the current run.
  </Card>

  <Card title="remove_verification()" icon="function" href="../functions/Agent-remove_verification">
    Remove a verification hook by name. Returns True if one was removed.
  </Card>

  <Card title="get_available_tools()" icon="function" href="../functions/Agent-get_available_tools">
    Get tools available to this agent, filtered by plan\_mode if enabled.
  </Card>

  <Card title="add_mcp_server()" icon="function" href="../functions/Agent-add_mcp_server">
    Attach an MCP server to a live agent at runtime.
  </Card>

  <Card title="remove_mcp_server()" icon="function" href="../functions/Agent-remove_mcp_server">
    Disconnect and deregister a previously attached MCP server.
  </Card>

  <Card title="refresh_tools()" icon="function" href="../functions/Agent-refresh_tools">
    Re-derive the live toolset from `self.tools`.
  </Card>

  <Card title="list_mcp_servers()" icon="function" href="../functions/Agent-list_mcp_servers">
    Return the names of MCP servers currently attached at runtime.
  </Card>

  <Card title="rules_manager()" icon="function" href="../functions/Agent-rules_manager">
    Lazy-initialized RulesManager for persistent rules/instructions.
  </Card>

  <Card title="get_rules_context()" icon="function" href="../functions/Agent-get_rules_context">
    Get rules context for the current conversation.
  </Card>

  <Card title="get_memory_context()" icon="function" href="../functions/Agent-get_memory_context">
    Get memory context for the current conversation.
  </Card>

  <Card title="get_learn_context()" icon="function" href="../functions/Agent-get_learn_context">
    Get learning context for injection into system prompt.
  </Card>

  <Card title="store_memory()" icon="function" href="../functions/Agent-store_memory">
    Store content in memory.
  </Card>

  <Card title="llm_model()" icon="function" href="../functions/Agent-llm_model">
    Unified property to get the LLM model regardless of configuration type.
  </Card>

  <Card title="retrieval_config()" icon="function" href="../functions/Agent-retrieval_config">
    Get the unified retrieval configuration.
  </Card>

  <Card title="rag()" icon="function" href="../functions/Agent-rag">
    Lazy-loaded RAG instance for advanced retrieval with citations.
  </Card>

  <Card title="retrieve()" icon="function" href="../functions/Agent-retrieve">
    Retrieve context from knowledge without LLM generation.
  </Card>

  <Card title="query()" icon="function" href="../functions/Agent-query">
    Query knowledge and get a structured answer with citations.
  </Card>

  <Card title="rag_query()" icon="function" href="../functions/Agent-rag_query">
    Query knowledge using RAG pipeline with citations.
  </Card>

  <Card title="chat_with_context()" icon="function" href="../functions/Agent-chat_with_context">
    Chat with pre-retrieved context.
  </Card>

  <Card title="close()" icon="function" href="../functions/Agent-close">
    Synchronously close the agent and clean up resources.
  </Card>

  <Card title="aclose()" icon="function" href="../functions/Agent-aclose">
    Async version of close() for async context managers.
  </Card>

  <Card title="is_closed()" icon="function" href="../functions/Agent-is_closed">
    Returns True if the agent has been closed.
  </Card>

  <Card title="where_does_it_run()" icon="function" href="../functions/Agent-where_does_it_run">
    Plain-English answer to 'where does my code actually run?'.
  </Card>
</CardGroup>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/agent/agent.py#L247">
  `praisonaiagents/agent/agent.py` at line 247
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Agents Concept" icon="robot" href="/docs/docs/concepts/agents" />

  <Card title="Single Agent Guide" icon="book-open" href="/docs/docs/guides/single-agent" />

  <Card title="Multi-Agent Guide" icon="users" href="/docs/docs/guides/multi-agent" />

  <Card title="Agent Configuration" icon="gear" href="/docs/docs/configuration/agent-config" />

  <Card title="Auto Agents" icon="wand-magic-sparkles" href="/docs/docs/features/autoagents" />
</CardGroup>
