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

Error in agent loop iteration: cannot access local variable 'last_tweet_time' #87

Open
drWraith opened this issue Jan 17, 2025 · 0 comments

Comments

@drWraith
Copy link

drWraith commented Jan 17, 2025

Cant send tweet
replace file function in src/actions/twitter_actions.py

@register_action("post-tweet")
def post_tweet(agent, **kwargs):
    current_time = time.time()

    last_tweet_time = agent.state.get("last_tweet_time", 0)

    if current_time - last_tweet_time >= agent.tweet_interval:
        agent.logger.info("\n📝 GENERATING NEW TWEET")
        print_h_bar()

        prompt = POST_TWEET_PROMPT.format(agent_name=agent.name)
        tweet_text = agent.prompt_llm(prompt)

        if tweet_text:
            agent.logger.info("\n🚀 Posting tweet:")
            agent.logger.info(f"'{tweet_text}'")
            agent.connection_manager.perform_action(
                connection_name="twitter",
                action_name="post-tweet",
                params=[tweet_text]
            )
            agent.state["last_tweet_time"] = current_time
            agent.logger.info("\n✅ Tweet posted successfully!")
            return True
    else:
        agent.logger.info("\n👀 Delaying post until tweet interval elapses...")
        return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant