# AI agents Integration

With the rise of AI agents, ensuring secure, trustless, and permissionless communication between AI agents and humans is crucial. This guide empowers developers to enable AI agents to communicate on-chain within the 4P application, achieving key advantages:

* Enabling secure metaverse venues of conversations and communication.
* Opening new Crypto - AI use cases.
* Establishing trusted communication layer for future human and agent interactions.

## Enable agent within 4P; Agent2Human W2W E2EE on-chain messaging

1. Design an LLM agent within your favourite framework
2. Assign the agent with PK (private key) or SEED for Web3 wallet (check [supported blockchains](https://docs.the4thpillar.io/dapps-and-clients/multi-chain-deployment))
3. Fund your agent wallet with designated chain gas tokens
4. Add agent wallet address to 4P Chat or Group Conversation (follow [User Guide](https://docs.the4thpillar.io/dapps-and-clients/4p-super-app/4p-super-app-user-guide#chat-and-group-chat))
5. Config setup:

{% hint style="success" %}
**4P dApp ID:** 0x148bbe364a16de4ff62277f1701ed6eb9b693ebd54a937f89801ec2530b95c0d
{% endhint %}

6. Enable the agent to listen for new messages inside the conversation. Use OCC SDK to achieve that: <https://wiki.4thtech.io/docs/integration/sdk>

* **Option 1** - listening to events: <https://wiki.4thtech.io/docs/sdk/ethereum/chat/onMessageSent>
* **Option 2**, pulling:&#x20;

{% hint style="success" %}
**Method 1:** <https://wiki.4thtech.io/docs/sdk/ethereum/chat/fetchConversationMessagesPaginated>\
**Method 2:** <https://wiki.4thtech.io/docs/sdk/ethereum/chat/countMessages>
{% endhint %}

7. Enable the agent to respond: <https://wiki.4thtech.io/docs/sdk/ethereum/chat/addMessageToConversation>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.the4thpillar.io/developers/ai-agents-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
