Skip to content

Commit

Permalink
Merge pull request #1403 from goat-sdk/goat-v2
Browse files Browse the repository at this point in the history
feat: improve GOAT integration by allowing tool calling when using generateText
  • Loading branch information
monilpat authored Jan 2, 2025
2 parents 9ea2449 + 5c4f44b commit 2b6c6a9
Show file tree
Hide file tree
Showing 9 changed files with 1,950 additions and 1,541 deletions.
5 changes: 3 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ export async function createAgent(
}

let goatPlugin: any | undefined;
if (getSecret(character, "EVM_PROVIDER_URL")) {

if (getSecret(character, "EVM_PRIVATE_KEY")) {
goatPlugin = await createGoatPlugin((secret) =>
getSecret(character, secret)
);
Expand Down Expand Up @@ -587,7 +588,7 @@ export async function createAgent(
getSecret(character, "COINBASE_NOTIFICATION_URI")
? webhookPlugin
: null,
getSecret(character, "EVM_PROVIDER_URL") ? goatPlugin : null,
goatPlugin,
getSecret(character, "ABSTRACT_PRIVATE_KEY")
? abstractPlugin
: null,
Expand Down
50 changes: 50 additions & 0 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import {
generateObject as aiGenerateObject,
generateText as aiGenerateText,
CoreTool,
GenerateObjectResult,
StepResult as AIStepResult,
} from "ai";
import { Buffer } from "buffer";
import { createOllama } from "ollama-ai-provider";
Expand Down Expand Up @@ -39,6 +41,9 @@ import {
import { fal } from "@fal-ai/client";
import { tavily } from "@tavily/core";

type Tool = CoreTool<any, any>;
type StepResult = AIStepResult<any>;

/**
* Send a message to the model for a text generateText - receive a string back and parse how you'd like
* @param opts - The options for the generateText request.
Expand All @@ -56,12 +61,18 @@ export async function generateText({
runtime,
context,
modelClass,
tools = {},
onStepFinish,
maxSteps = 1,
stop,
customSystemPrompt,
}: {
runtime: IAgentRuntime;
context: string;
modelClass: string;
tools?: Record<string, Tool>;
onStepFinish?: (event: StepResult) => Promise<void> | void;
maxSteps?: number;
stop?: string[];
customSystemPrompt?: string;
}): Promise<string> {
Expand Down Expand Up @@ -210,6 +221,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand All @@ -235,6 +249,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand Down Expand Up @@ -262,6 +279,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand Down Expand Up @@ -289,6 +309,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand Down Expand Up @@ -320,6 +343,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand All @@ -343,6 +369,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
Expand Down Expand Up @@ -395,6 +424,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
Expand Down Expand Up @@ -423,6 +455,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
Expand All @@ -449,7 +484,10 @@ export async function generateText({
const { text: ollamaResponse } = await aiGenerateText({
model: ollama,
prompt: context,
tools: tools,
onStepFinish: onStepFinish,
temperature: temperature,
maxSteps: maxSteps,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
Expand Down Expand Up @@ -477,8 +515,11 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
temperature: temperature,
maxTokens: max_response_length,
maxSteps: maxSteps,
frequencyPenalty: frequency_penalty,
presencePenalty: presence_penalty,
experimental_telemetry: experimental_telemetry,
Expand Down Expand Up @@ -527,6 +568,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand Down Expand Up @@ -554,6 +598,9 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
maxSteps: maxSteps,
temperature: temperature,
maxTokens: max_response_length,
frequencyPenalty: frequency_penalty,
Expand All @@ -580,7 +627,10 @@ export async function generateText({
runtime.character.system ??
settings.SYSTEM_PROMPT ??
undefined,
tools: tools,
onStepFinish: onStepFinish,
temperature: temperature,
maxSteps: maxSteps,
maxTokens: max_response_length,
});

Expand Down
21 changes: 19 additions & 2 deletions packages/plugin-goat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ A plugin for integrating blockchain capabilities through the GOAT (Great Onchain

[GOAT](https://ohmygoat.dev/) 🐐 (Great Onchain Agent Toolkit) is an open-source framework for adding blockchain tools such as wallets, being able to hold or trade tokens, or interacting with blockchain smart contracts, to your AI agent.

This plugin integrates GOAT with Eliza, giving your agent the ability to interact with many different protocols. The current setup adds onchain capabilities to your agent to send and check balances of ETH and USDC. Add all the capabilities you need by adding more plugins (read below for more information)!
- [Chains supported](https://ohmygoat.dev/chains-wallets-plugins)
- [Plugins supported](https://ohmygoat.dev/chains-wallets-plugins)

This plugin integrates GOAT with Eliza, giving your agent the ability to interact with many different protocols. The current setup adds onchain capabilities to your agent to send and check balances of ETH and USDC, and to swap tokens using KIM protocol. Add all the capabilities you need by adding more plugins (read below for more information)!

## Installation

Expand All @@ -25,7 +28,21 @@ EVM_PROVIDER_URL=<Your RPC provider URL (e.g., Infura, Alchemy)>
## Configure GOAT for your use case

1. Configure the chain you want to use by updating the `wallet.ts` file (see all available chains at [https://ohmygoat.dev/chains](https://ohmygoat.dev/chains))
2. Add the plugins you need to your `getOnChainActions` function:
2. Specify the actions you want to have by updating the `actions.ts` file
3. Add the plugins you need to perform these actions to the `getOnChainTools` function (uniswap, polymarket, etc. see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-plugins))
4. Build the project running `pnpm build`
5. Add the necessary environment variables to set up your wallet and plugins
6. Run your agent!

## Common Issues
1. **Agent not executing an action**:
- If you are also using the EVM Plugin, sometimes the agent might confuse the action name with an EVM Plugin action name instead of the GOAT Plugin action. Removing the EVM Plugin should fix this issue. There is no need for you to use both plugins at the same time.
- If you are using Trump as a character it might be tricky to get them to perform any action since the character is full of prompts that aim to change the topic of the conversation. To fix this try using a different character or create your own with prompts that are more suitable to what the agent is supposed to do.

## Plugins
GOAT itself has several plugins for interacting with different protocols such as Polymarket, Uniswap, and many more. (see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-plugins))

You can easily add them by installing them and adding them to the `getOnChainActions` function:

```typescript
const tools = getOnChainActions({
Expand Down
43 changes: 23 additions & 20 deletions packages/plugin-goat/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"name": "@elizaos/plugin-goat",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@goat-sdk/core": "0.3.8",
"@goat-sdk/plugin-coingecko": "0.1.4",
"@goat-sdk/plugin-erc20": "0.1.7",
"@goat-sdk/wallet-viem": "0.1.3",
"tsup": "8.3.5"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch"
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
"name": "@elizaos/plugin-goat",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@goat-sdk/adapter-vercel-ai": "0.2.0",
"@goat-sdk/core": "0.4.0",
"@goat-sdk/plugin-erc20": "0.2.2",
"@goat-sdk/plugin-kim": "0.1.2",
"@goat-sdk/wallet-evm": "0.2.0",
"@goat-sdk/wallet-viem": "0.2.0",
"tsup": "8.3.5",
"viem": "2.21.53"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch"
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
Loading

0 comments on commit 2b6c6a9

Please sign in to comment.