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

# autogen.agentchat.contrib.graph_rag.GraphRagCapability

<h2 id="autogen.agentchat.contrib.graph_rag.GraphRagCapability" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">GraphRagCapability</span>
</h2>

```python theme={null}
GraphRagCapability(query_engine: GraphQueryEngine)
```

A graph-based RAG capability uses a graph query engine to give a conversable agent the graph-based RAG ability.<br />An agent class with graph-based RAG capability could

1. create a graph in the underlying database with input documents.<br />2. retrieved relevant information based on messages received by the agent.<br />3. generate answers from retrieved information and send messages back.<br />For example,

```python theme={null}
graph_query_engine = GraphQueryEngine(...)
graph_query_engine.init_db([Document(doc1), Document(doc2), ...])

graph_rag_agent = ConversableAgent(
    name="graph_rag_agent",
    max_consecutive_auto_reply=3,
    ...<br/>)
graph_rag_capability = GraphRagCapbility(graph_query_engine)
graph_rag_capability.add_to_agent(graph_rag_agent)

user_proxy = UserProxyAgent(
    name="user_proxy",
    code_execution_config=False,
    is_termination_msg=lambda msg: "TERMINATE" in msg["content"],
    human_input_mode="ALWAYS",
)
user_proxy.initiate_chat(graph_rag_agent, message="Name a few actors who've played in 'The Matrix'")

# ChatResult(
    # chat_id=None,
    # chat_history=[
        # \{'content': 'Name a few actors who've played in 'The Matrix'', 'role': 'graph_rag_agent'},
        # \{'content': 'A few actors who have played in The Matrix are: <br/>        #   - Keanu Reeves
        #   - Laurence Fishburne
        #   - Carrie-Anne Moss
        #   - Hugo Weaving',
        #   'role': 'user_proxy'},
    # ...)
```

Initialize graph-based RAG capability with a graph query engine

<b>Parameters:</b>

| Name           | Description                                                                                                               |
| -------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `query_engine` | **Type:** [GraphQueryEngine](/docs/api-reference/autogen/agentchat/contrib/graph_rag/graph_query_engine/GraphQueryEngine) |

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### add\_to\_agent

```python theme={null}
add_to_agent(self, agent: ConversableAgent) -> None
```

Add the capability to an agent

<b>Parameters:</b>

| Name    | Description                                                                |
| ------- | -------------------------------------------------------------------------- |
| `agent` | **Type:** [ConversableAgent](/docs/api-reference/autogen/ConversableAgent) |

<br />
