You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining a twitterShouldRespondTemplate in a character’s JSON configuration file, the code attempts to invoke it as a function with (validTargetUsersStr). Since JSON cannot store JavaScript functions, this causes runtime errors. Other templates like twitterMessageHandlerTemplate and twitterPostTemplate are handled purely as strings, so they work fine. The inconsistency leads to broken response generation when a JSON-defined twitterShouldRespondTemplate is present.
To Reproduce
Create a character JSON file (e.g., adam.character.json) that includes:
{
"name": "your-character-name",
"clients": ["telegram", "twitter"],
"modelProvider": "openai",
"settings": {
"secrets": {
"TELEGRAM_BOT_TOKEN": "your_telegram_bot_token",
"TWITTER_USERNAME": "user",
"TWITTER_EMAIL": "email@proton.me",
"TWITTER_PASSWORD": "your_twitter_password",
"TWITTER_COOKIES": "[{\"key\":\"auth_token\",\"value\":\"your_auth_token\",\"domain\":\".twitter.com\"}, {\"key\":\"ct0\",\"value\":\"your_ct0_value\",\"domain\":\".twitter.com\"}, {\"key\":\"guest_id\",\"value\":\"v1%3A173451270913595996\",\"domain\":\".twitter.com\"}]",
"TWITTER_TARGET_USERS": "user1,user2"
}
},
"plugins": [
"@ai16z/plugin-your-custom-plugin"
],
"templates": {
"twitterPostTemplate": "# Areas of Expertise\n{{knowledge}}\n\n# About {{agentName}} (@{{twitterUserName}}):\n{{bio}}\n{{lore}}\n{{topics}}\n\n{{providers}}\n\n{{characterPostExamples}}\n\n{{postDirections}}\n\n# Task: Generate a post in the voice and style and perspective of {{agentName}} @{{twitterUserName}}.\nWrite a 1-3 sentence post that is {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Do not add commentary or acknowledge this request, just write the post.\nYour response should not contain any questions. Brief, concise statements only. The total character count MUST be less than {{maxTweetLength}}. No emojis. Use \\n\\n (double spaces) between statements.",
"twitterMessageHandlerTemplate": "# Areas of Expertise\n{{knowledge}}\n\n# About {{agentName}} (@{{twitterUserName}}):\n{{bio}}\n{{lore}}\n{{topics}}\n\n{{providers}}\n\n{{characterPostExamples}}\n\n{{postDirections}}\n\nRecent interactions between {{agentName}} and other users:\n{{recentPostInteractions}}\n\n{{recentPosts}}\n\n# Task: Generate a post/reply in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}) while using the thread of tweets as additional context:\nCurrent Post:\n{{currentPost}}\n\nThread of Tweets You Are Replying To:\n{{formattedConversation}}\n\n{{actions}}\n# Task: Generate a post in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}). You MUST include an action if the current post text includes a prompt that is similar to one of the available actions mentioned here:\n{{actionNames}}\nHere is the current post text again. Remember to include an action if the current post text includes a prompt that asks for one of the available actions mentioned above (does not need to be exact)\n{{currentPost}}\n\nResponse format should be formatted in a JSON block like this:\n```json\n{ \"user\": \"{{agentName}}\", \"text\": \"string\", \"action\": \"string\" }\n```",
"twitterShouldRespondTemplate": "# INSTRUCTIONS: Determine if {{agentName}} (@{{twitterUserName}}) should respond to the message and participate in the conversation.\n\nResponse options are RESPOND, IGNORE and STOP.\n\nPRIORITY RULE: ALWAYS RESPOND to these users regardless of topic or message content: {{targetUsersStr}}. Topic relevance should be ignored for these users.\n\nFor other users:\n- {{agentName}} should RESPOND to messages directed at them\n- {{agentName}} should RESPOND to conversations relevant to their background\n- {{agentName}} should IGNORE irrelevant messages\n- {{agentName}} should IGNORE very short messages unless directly addressed\n- {{agentName}} should STOP if asked to stop\n- {{agentName}} should STOP if conversation is concluded\n- {{agentName}} is in a room with other users and wants to be conversational, but not annoying.\n\n{{recentPosts}}\n\nIMPORTANT: For users not in the priority list, {{agentName}} (@{{twitterUserName}}) should err on the side of IGNORE rather than RESPOND if in doubt.\n\n{{recentPosts}}\n\nIMPORTANT: {{agentName}} (aka @{{twitterUserName}}) is particularly sensitive about being annoying, so if there is any doubt, it is better to IGNORE than to RESPOND.\n\n{{currentPost}}\n\nThread of Tweets You Are Replying To:\n{{formattedConversation}}\n\n# INSTRUCTIONS: Respond with [RESPOND] if {{agentName}} should respond, or [IGNORE] if {{agentName}} should not respond to the last message and [STOP] if {{agentName}} should stop participating in the conversation.\n\nThe available options are [RESPOND], [IGNORE], or [STOP]. Choose the most appropriate option.\nIf {{agentName}} is talking too much, you can choose [IGNORE]\n\nYour response must include one of the options."
}
}
Run the agent with this character file.
Observe the failure: The agent does not respond as expected because it attempts to call twitterShouldRespondTemplate(validTargetUsersStr) as a function, leading to errors since the template is defined as a string.
Expected behavior
twitterShouldRespondTemplate should be handled consistently with other templates like twitterMessageHandlerTemplate and twitterPostTemplate.
If it’s defined as a string, it should not be invoked as a function.
The code should either:
Treat all templates as strings and handle variable interpolation through composeContext, or
Allow defining templates as functions through a different configuration method (not JSON).
Additional context
Workaround: Removing twitterShouldRespondTemplate from the JSON file allows the system to fallback to the built-in twitterShouldRespondTemplate function, which works as intended.
Potential Fixes:
Option 1: Modify the agent's code to treat twitterShouldRespondTemplate as a string if it's defined in the JSON, avoiding the function call.
Option 2: Allow templates to be defined as functions through a different configuration approach, such as a JavaScript/TypeScript file instead of JSON.
Option 3: Provide a hybrid approach where the JSON can reference external functions or use placeholders that composeContext can replace without needing to call them as functions.
Summary:
twitterShouldRespondTemplate is treated differently in the code by attempting to invoke it as a function with validTargetUsersStr, whereas other templates are handled as plain strings.
Since JSON cannot store functions, defining twitterShouldRespondTemplate as a string in the JSON configuration leads to runtime errors and broken response logic.
To resolve the issue, either remove the custom twitterShouldRespondTemplate from the JSON to use the fallback function or adjust the code to handle twitterShouldRespondTemplate as a string, ensuring consistent template processing.
The text was updated successfully, but these errors were encountered:
blockfer-rp
changed the title
=: twitterShouldRespondTemplate Fails When Defined as a String in JSON Character Config
twitterShouldRespondTemplate Fails When Defined as a String in JSON Character Config
Dec 19, 2024
Describe the bug
When defining a
twitterShouldRespondTemplate
in a character’s JSON configuration file, the code attempts to invoke it as a function with(validTargetUsersStr)
. Since JSON cannot store JavaScript functions, this causes runtime errors. Other templates liketwitterMessageHandlerTemplate
andtwitterPostTemplate
are handled purely as strings, so they work fine. The inconsistency leads to broken response generation when a JSON-definedtwitterShouldRespondTemplate
is present.To Reproduce
Create a character JSON file (e.g.,
adam.character.json
) that includes:twitterShouldRespondTemplate(validTargetUsersStr)
as a function, leading to errors since the template is defined as a string.Expected behavior
twitterShouldRespondTemplate
should be handled consistently with other templates liketwitterMessageHandlerTemplate
andtwitterPostTemplate
.If it’s defined as a string, it should not be invoked as a function.
The code should either:
composeContext
, orAdditional context
Workaround: Removing
twitterShouldRespondTemplate
from the JSON file allows the system to fallback to the built-intwitterShouldRespondTemplate
function, which works as intended.Potential Fixes:
twitterShouldRespondTemplate
as a string if it's defined in the JSON, avoiding the function call.composeContext
can replace without needing to call them as functions.Summary:
twitterShouldRespondTemplate
is treated differently in the code by attempting to invoke it as a function withvalidTargetUsersStr
, whereas other templates are handled as plain strings.twitterShouldRespondTemplate
as a string in the JSON configuration leads to runtime errors and broken response logic.twitterShouldRespondTemplate
from the JSON to use the fallback function or adjust the code to handletwitterShouldRespondTemplate
as a string, ensuring consistent template processing.The text was updated successfully, but these errors were encountered: