Skip to content

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

@drWraith

Description

@drWraith

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions