Agent posts multiple tweets instead of one when running actions like crypto search #4426
Replies: 2 comments 2 replies
-
|
I believe you can (system) prompt engineer your way out of this one. |
Beta Was this translation helpful? Give feedback.
-
|
The issue is that your action is likely calling the 1. Use a Single CallbackInstead of calling const cryptoPriceAction: Action = {
name: 'GET_CRYPTO_PRICE',
description: 'Fetch crypto prices',
handler: async (runtime, message, state, options, callback) => {
try {
// DON'T do this (causes multiple tweets):
// await callback({ text: 'Retrieving crypto prices...' });
// Fetch all data first
const priceData = await fetchCryptoPrices();
// Make ONE callback with complete response
await callback({
text: `Current crypto prices: ${priceData}`,
actions: ['GET_CRYPTO_PRICE']
});
return true;
} catch (error) {
await callback({
text: 'Sorry, I couldn\'t fetch the crypto prices right now.'
});
return false;
}
}
};2. Avoid Streaming ResponsesThe documentation shows examples of streaming responses that make multiple callbacks. For Twitter, avoid this pattern: // DON'T do this for Twitter:
await callback({ text: 'Let me check that for you...' });
const result = await fetchData();
await callback({ text: `Here's what I found: ${result}` });3. Handle Loading States InternallyIf you need to show progress, handle it internally without using callbacks: const marketDataAction: Action = {
name: 'GET_MARKET_DATA',
handler: async (runtime, message, state, options, callback) => {
// Show loading internally (no callback)
console.log('Fetching market data...');
// Gather all data
const [stocks, crypto, news] = await Promise.all([
fetchStockData(),
fetchCryptoData(),
fetchNewsData()
]);
// Single comprehensive response
const response = `📊 Market Update:
Stocks: ${stocks}
Crypto: ${crypto}
News: ${news}`;
// ONE callback only
await callback({ text: response });
return true;
}
};4. Use the
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, how can I make the agent go through certain actions before replying to a tweet?
I created an action to fetch crypto prices and it works, but the issue is that the agent replies to the tweet first saying it’s retrieving the info, and then makes a second tweet with the actual data.
Is there a way to prevent this behavior? I plan to add more actions for markets, stocks, daily news, and so o, but I don’t want the agent to post 2 or 3 tweets just to provide a price or a news update. I’d like it to respond with a single tweet only.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions