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
5 changes: 3 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,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 @@ -574,7 +575,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 @@ -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 @@ -203,6 +214,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 @@ -226,6 +240,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 @@ -252,6 +269,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 @@ -278,6 +298,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 @@ -308,6 +331,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 @@ -330,6 +356,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 @@ -381,6 +410,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 @@ -408,6 +440,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 @@ -433,7 +468,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 @@ -459,8 +497,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 @@ -508,6 +549,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 @@ -534,6 +578,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 @@ -559,7 +606,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
10 changes: 6 additions & 4 deletions packages/plugin-goat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"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",
"@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"
},
Expand Down
Loading
Loading