Skip to content

Commit 2b6c6a9

Browse files
authored
Merge pull request #1403 from goat-sdk/goat-v2
feat: improve GOAT integration by allowing tool calling when using generateText
2 parents 9ea2449 + 5c4f44b commit 2b6c6a9

File tree

9 files changed

+1950
-1541
lines changed

9 files changed

+1950
-1541
lines changed

agent/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ export async function createAgent(
509509
}
510510

511511
let goatPlugin: any | undefined;
512-
if (getSecret(character, "EVM_PROVIDER_URL")) {
512+
513+
if (getSecret(character, "EVM_PRIVATE_KEY")) {
513514
goatPlugin = await createGoatPlugin((secret) =>
514515
getSecret(character, secret)
515516
);
@@ -587,7 +588,7 @@ export async function createAgent(
587588
getSecret(character, "COINBASE_NOTIFICATION_URI")
588589
? webhookPlugin
589590
: null,
590-
getSecret(character, "EVM_PROVIDER_URL") ? goatPlugin : null,
591+
goatPlugin,
591592
getSecret(character, "ABSTRACT_PRIVATE_KEY")
592593
? abstractPlugin
593594
: null,

packages/core/src/generation.ts

+50
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
66
import {
77
generateObject as aiGenerateObject,
88
generateText as aiGenerateText,
9+
CoreTool,
910
GenerateObjectResult,
11+
StepResult as AIStepResult,
1012
} from "ai";
1113
import { Buffer } from "buffer";
1214
import { createOllama } from "ollama-ai-provider";
@@ -39,6 +41,9 @@ import {
3941
import { fal } from "@fal-ai/client";
4042
import { tavily } from "@tavily/core";
4143

44+
type Tool = CoreTool<any, any>;
45+
type StepResult = AIStepResult<any>;
46+
4247
/**
4348
* Send a message to the model for a text generateText - receive a string back and parse how you'd like
4449
* @param opts - The options for the generateText request.
@@ -56,12 +61,18 @@ export async function generateText({
5661
runtime,
5762
context,
5863
modelClass,
64+
tools = {},
65+
onStepFinish,
66+
maxSteps = 1,
5967
stop,
6068
customSystemPrompt,
6169
}: {
6270
runtime: IAgentRuntime;
6371
context: string;
6472
modelClass: string;
73+
tools?: Record<string, Tool>;
74+
onStepFinish?: (event: StepResult) => Promise<void> | void;
75+
maxSteps?: number;
6576
stop?: string[];
6677
customSystemPrompt?: string;
6778
}): Promise<string> {
@@ -210,6 +221,9 @@ export async function generateText({
210221
runtime.character.system ??
211222
settings.SYSTEM_PROMPT ??
212223
undefined,
224+
tools: tools,
225+
onStepFinish: onStepFinish,
226+
maxSteps: maxSteps,
213227
temperature: temperature,
214228
maxTokens: max_response_length,
215229
frequencyPenalty: frequency_penalty,
@@ -235,6 +249,9 @@ export async function generateText({
235249
runtime.character.system ??
236250
settings.SYSTEM_PROMPT ??
237251
undefined,
252+
tools: tools,
253+
onStepFinish: onStepFinish,
254+
maxSteps: maxSteps,
238255
temperature: temperature,
239256
maxTokens: max_response_length,
240257
frequencyPenalty: frequency_penalty,
@@ -262,6 +279,9 @@ export async function generateText({
262279
runtime.character.system ??
263280
settings.SYSTEM_PROMPT ??
264281
undefined,
282+
tools: tools,
283+
onStepFinish: onStepFinish,
284+
maxSteps: maxSteps,
265285
temperature: temperature,
266286
maxTokens: max_response_length,
267287
frequencyPenalty: frequency_penalty,
@@ -289,6 +309,9 @@ export async function generateText({
289309
runtime.character.system ??
290310
settings.SYSTEM_PROMPT ??
291311
undefined,
312+
tools: tools,
313+
onStepFinish: onStepFinish,
314+
maxSteps: maxSteps,
292315
temperature: temperature,
293316
maxTokens: max_response_length,
294317
frequencyPenalty: frequency_penalty,
@@ -320,6 +343,9 @@ export async function generateText({
320343
runtime.character.system ??
321344
settings.SYSTEM_PROMPT ??
322345
undefined,
346+
tools: tools,
347+
onStepFinish: onStepFinish,
348+
maxSteps: maxSteps,
323349
temperature: temperature,
324350
maxTokens: max_response_length,
325351
frequencyPenalty: frequency_penalty,
@@ -343,6 +369,9 @@ export async function generateText({
343369
runtime.character.system ??
344370
settings.SYSTEM_PROMPT ??
345371
undefined,
372+
tools: tools,
373+
onStepFinish: onStepFinish,
374+
maxSteps: maxSteps,
346375
maxTokens: max_response_length,
347376
frequencyPenalty: frequency_penalty,
348377
presencePenalty: presence_penalty,
@@ -395,6 +424,9 @@ export async function generateText({
395424
runtime.character.system ??
396425
settings.SYSTEM_PROMPT ??
397426
undefined,
427+
tools: tools,
428+
onStepFinish: onStepFinish,
429+
maxSteps: maxSteps,
398430
maxTokens: max_response_length,
399431
frequencyPenalty: frequency_penalty,
400432
presencePenalty: presence_penalty,
@@ -423,6 +455,9 @@ export async function generateText({
423455
runtime.character.system ??
424456
settings.SYSTEM_PROMPT ??
425457
undefined,
458+
tools: tools,
459+
onStepFinish: onStepFinish,
460+
maxSteps: maxSteps,
426461
maxTokens: max_response_length,
427462
frequencyPenalty: frequency_penalty,
428463
presencePenalty: presence_penalty,
@@ -449,7 +484,10 @@ export async function generateText({
449484
const { text: ollamaResponse } = await aiGenerateText({
450485
model: ollama,
451486
prompt: context,
487+
tools: tools,
488+
onStepFinish: onStepFinish,
452489
temperature: temperature,
490+
maxSteps: maxSteps,
453491
maxTokens: max_response_length,
454492
frequencyPenalty: frequency_penalty,
455493
presencePenalty: presence_penalty,
@@ -477,8 +515,11 @@ export async function generateText({
477515
runtime.character.system ??
478516
settings.SYSTEM_PROMPT ??
479517
undefined,
518+
tools: tools,
519+
onStepFinish: onStepFinish,
480520
temperature: temperature,
481521
maxTokens: max_response_length,
522+
maxSteps: maxSteps,
482523
frequencyPenalty: frequency_penalty,
483524
presencePenalty: presence_penalty,
484525
experimental_telemetry: experimental_telemetry,
@@ -527,6 +568,9 @@ export async function generateText({
527568
runtime.character.system ??
528569
settings.SYSTEM_PROMPT ??
529570
undefined,
571+
tools: tools,
572+
onStepFinish: onStepFinish,
573+
maxSteps: maxSteps,
530574
temperature: temperature,
531575
maxTokens: max_response_length,
532576
frequencyPenalty: frequency_penalty,
@@ -554,6 +598,9 @@ export async function generateText({
554598
runtime.character.system ??
555599
settings.SYSTEM_PROMPT ??
556600
undefined,
601+
tools: tools,
602+
onStepFinish: onStepFinish,
603+
maxSteps: maxSteps,
557604
temperature: temperature,
558605
maxTokens: max_response_length,
559606
frequencyPenalty: frequency_penalty,
@@ -580,7 +627,10 @@ export async function generateText({
580627
runtime.character.system ??
581628
settings.SYSTEM_PROMPT ??
582629
undefined,
630+
tools: tools,
631+
onStepFinish: onStepFinish,
583632
temperature: temperature,
633+
maxSteps: maxSteps,
584634
maxTokens: max_response_length,
585635
});
586636

packages/plugin-goat/README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ A plugin for integrating blockchain capabilities through the GOAT (Great Onchain
66

77
[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.
88

9-
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)!
9+
- [Chains supported](https://ohmygoat.dev/chains-wallets-plugins)
10+
- [Plugins supported](https://ohmygoat.dev/chains-wallets-plugins)
11+
12+
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)!
1013

1114
## Installation
1215

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

2730
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))
28-
2. Add the plugins you need to your `getOnChainActions` function:
31+
2. Specify the actions you want to have by updating the `actions.ts` file
32+
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))
33+
4. Build the project running `pnpm build`
34+
5. Add the necessary environment variables to set up your wallet and plugins
35+
6. Run your agent!
36+
37+
## Common Issues
38+
1. **Agent not executing an action**:
39+
- 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.
40+
- 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.
41+
42+
## Plugins
43+
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))
44+
45+
You can easily add them by installing them and adding them to the `getOnChainActions` function:
2946

3047
```typescript
3148
const tools = getOnChainActions({

packages/plugin-goat/package.json

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
{
2-
"name": "@elizaos/plugin-goat",
3-
"version": "0.1.7-alpha.2",
4-
"main": "dist/index.js",
5-
"type": "module",
6-
"types": "dist/index.d.ts",
7-
"dependencies": {
8-
"@elizaos/core": "workspace:*",
9-
"@goat-sdk/core": "0.3.8",
10-
"@goat-sdk/plugin-coingecko": "0.1.4",
11-
"@goat-sdk/plugin-erc20": "0.1.7",
12-
"@goat-sdk/wallet-viem": "0.1.3",
13-
"tsup": "8.3.5"
14-
},
15-
"scripts": {
16-
"build": "tsup --format esm --dts",
17-
"dev": "tsup --format esm --dts --watch"
18-
},
19-
"peerDependencies": {
20-
"whatwg-url": "7.1.0"
21-
}
2+
"name": "@elizaos/plugin-goat",
3+
"version": "0.1.7-alpha.2",
4+
"main": "dist/index.js",
5+
"type": "module",
6+
"types": "dist/index.d.ts",
7+
"dependencies": {
8+
"@elizaos/core": "workspace:*",
9+
"@goat-sdk/adapter-vercel-ai": "0.2.0",
10+
"@goat-sdk/core": "0.4.0",
11+
"@goat-sdk/plugin-erc20": "0.2.2",
12+
"@goat-sdk/plugin-kim": "0.1.2",
13+
"@goat-sdk/wallet-evm": "0.2.0",
14+
"@goat-sdk/wallet-viem": "0.2.0",
15+
"tsup": "8.3.5",
16+
"viem": "2.21.53"
17+
},
18+
"scripts": {
19+
"build": "tsup --format esm --dts",
20+
"dev": "tsup --format esm --dts --watch"
21+
},
22+
"peerDependencies": {
23+
"whatwg-url": "7.1.0"
24+
}
2225
}

0 commit comments

Comments
 (0)