Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve GOAT integration by allowing tool calling when using generateText #1403

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export async function createAgent(
}

let goatPlugin: any | undefined;
if (getSecret(character, "ALCHEMY_API_KEY")) {
if (getSecret(character, "EVM_PRIVATE_KEY")) {
goatPlugin = await createGoatPlugin((secret) =>
getSecret(character, secret)
);
Expand Down Expand Up @@ -560,7 +560,7 @@ export async function createAgent(
getSecret(character, "COINBASE_NOTIFICATION_URI")
? webhookPlugin
: null,
getSecret(character, "ALCHEMY_API_KEY") ? goatPlugin : null,
goatPlugin,
getSecret(character, "FLOW_ADDRESS") &&
getSecret(character, "FLOW_PRIVATE_KEY")
? flowPlugin
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 @@ -37,6 +39,9 @@ import {
} from "./types.ts";
import { fal } from "@fal-ai/client";

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 @@ -54,11 +59,17 @@ export async function generateText({
runtime,
context,
modelClass,
tools = {},
onStepFinish,
maxSteps = 1,
stop,
}: {
runtime: IAgentRuntime;
context: string;
modelClass: string;
tools?: Record<string, Tool>;
onStepFinish?: (event: StepResult) => Promise<void> | void;
maxSteps?: number;
stop?: string[];
}): Promise<string> {
if (!context) {
Expand Down Expand Up @@ -192,6 +203,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 @@ -215,6 +229,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 @@ -241,6 +258,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 @@ -267,6 +287,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 @@ -297,6 +320,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 @@ -319,6 +345,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 @@ -370,6 +399,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 @@ -397,6 +429,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 @@ -422,7 +457,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 All @@ -448,8 +486,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,
});
Expand Down Expand Up @@ -497,6 +538,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 @@ -523,6 +567,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 @@ -548,7 +595,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
16 changes: 10 additions & 6 deletions packages/plugin-goat/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# GOAT Plugin
[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)!

## 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 (uniswap, polymarket, etc. see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-plugins))
3. Build the project running `pnpm build`
4. Add the necessary environment variables to set up your wallet and plugins
5. Run your agent!
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 more. (see all available plugins at [https://ohmygoat.dev/chains-wallets-plugins](https://ohmygoat.dev/chains-wallets-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:

Expand Down
44 changes: 23 additions & 21 deletions packages/plugin-goat/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "@elizaos/plugin-goat",
"version": "0.1.7-alpha.1",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@goat-sdk/core": "0.3.8",
"@goat-sdk/plugin-erc20": "0.1.7",
"@goat-sdk/wallet-viem": "0.1.3",
"@goat-sdk/plugin-coingecko": "0.1.4",
"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"
}
"name": "@elizaos/plugin-goat",
"version": "0.1.7-alpha.1",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"@goat-sdk/adapter-vercel-ai": "~0.2.0",
0xaguspunk marked this conversation as resolved.
Show resolved Hide resolved
"@goat-sdk/core": "~0.4.0",
"@goat-sdk/plugin-erc20": "~0.2.0",
"@goat-sdk/plugin-kim": "~0.1.0",
"@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
Loading