Skip to content

Commit

Permalink
Minor fixes to AI docs (#689)
Browse files Browse the repository at this point in the history
* Minor fixes to AI docs

* Restore ai folders introductions

* Implement requested changes

* Add agent setup tutorial & workshop as company resources

* Fix workshop youtube URL

* Re-generate code examples
  • Loading branch information
louis-md authored Feb 28, 2025
1 parent c1c4c17 commit 074a5d2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
28 changes: 28 additions & 0 deletions components/ResourceHub/company-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,33 @@
],
"image": "https://docs.safe.global/og_image.png",
"lastChecked": "2025-01-21"
},
{
"name": "Create an AI agent that can interact with your Safe",
"url": "https://docs.safe.global/home/ai-agent-setup",
"type": "Blog Post",
"date": "2025-02-11",
"description": "In this tutorial, we will learn how to set up and deploy an AI agent that has capabilities to access a Safe and prepare transactions for it 🤖.",
"tags": [
"Tutorial",
"Safe Core SDK",
"AI"
],
"lastChecked": "2025-02-13"
},
{
"name": "Workshop: Build reliable AI agents with Safe capabilities",
"url": "https://www.youtube.com/watch?v=y90oH7w8h8U",
"type": "Video",
"date": "2025-02-11",
"description": "In this Webinar, Safe developer Louis will provide an introduction into how to setup your AI agent with a Safe Smart Account.",
"tags": [
"Tutorial",
"Safe Core SDK",
"AI"
],
"lastChecked": "2025-02-13"
}
]


8 changes: 3 additions & 5 deletions examples/ai-agent/tools/safe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import Safe from "@safe-global/protocol-kit";
import { createPublicClient, http } from "viem";
import { createPublicClient, formatEther, http } from "viem";
import { sepolia } from "viem/chains";

export const getEthBalance = async ({ address, chainId }) => {
Expand All @@ -25,11 +25,9 @@ export const getEthBalance = async ({ address, chainId }) => {
const weiBalance = ethBalanceData.find(
(element) => element?.tokenAddress === null && element?.token === null
)?.balance;
const ethBalance = BigInt(weiBalance) / BigInt(10 ** 18); // Convert from wei to eth
const ethBalance = formatEther(weiBalance); // Convert from wei to eth

return `The current balance of the Safe Multisig at address ${address} is ${ethBalance.toLocaleString(
"en-US"
)} ETH.`;
return `The current balance of the Safe Multisig at address ${address} is ${ethBalance} ETH.`;
};

export const deployNewSafe = async () => {
Expand Down
8 changes: 5 additions & 3 deletions pages/home/ai-agent-quickstarts/basic-agent-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ const RPC_URL = 'https://rpc.ankr.com/eth_sepolia'
const safeClient = await Safe.init({
provider: RPC_URL,
signer: SIGNER_PRIVATE_KEY,
safeOptions: {
owners: [SIGNER_ADDRESS],
threshold: 1
predictedSafe: {
safeAccountConfig: {
owners: [SIGNER_ADDRESS],
threshold: 1
}
}
})
```
Expand Down
2 changes: 1 addition & 1 deletion pages/home/ai-agent-quickstarts/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ We describe these different setups:
1. [Basic Agent Setup](./basic-agent-setup.mdx): The simplest and fastest setup for your agent.
2. [Human Approval for agent actions](./human-approval.mdx): The AI agent proposes transactions, human signers approve and execute the transaction. Highest security, but not the fastest.
3. [Multi Agent Setup](./multi-agent-setup.mdx): Multiple Agents are signers of a Smart Account. They have to approve and execute each others transactions.
4. [Agent with a spending limit](./agent-with-spending-limit.mdx): An AI agent gets a spending limit on your treasury or DAO funds. This advanced setup allows fast transactions with a good amount of security.
4. [Agent with a spending limit](./agent-with-spending-limit.mdx): An AI agent gets a spending limit on your treasury or DAO funds. This advanced setup allows fast transactions with a good amount of security.
2 changes: 0 additions & 2 deletions pages/home/ai-agent-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Callout } from 'nextra/components'

# Create an AI agent that can interact with your Safe

At Safe, we envision a future where an important part of the onchain economy is driven by AI agents. We support this vision by organizing one of the [biggest AI x Crypto hackathons to date](https://agentathon.ai), as well as providing concrete [guides](./ai-agent-quickstarts/introduction) to help you get started.

In this tutorial, we will learn how to set up and deploy an AI agent that has capabilities to access a Safe and prepare transactions for it 🤖. We will use [LangChain](https://www.langchain.com/agents) to set up the agent, the [Protocol Kit](../sdk/protocol-kit.mdx) to interact with Safes, and [`ollama`](https://ollama.com/) to load and run the agents locally.

**Note:** If you wish to follow along using the completed project, you can [check out the GitHub repository](https://github.com/5afe/safe-ai-agent-tutorial) for this tutorial.
Expand Down

0 comments on commit 074a5d2

Please sign in to comment.