Skip to content

First implementation of a LangGraph agent for ChaosChain - #50

Draft
ginrod wants to merge 26 commits into
ChaosChain:masterfrom
ginrod:add-langgraph-agent
Draft

First implementation of a LangGraph agent for ChaosChain#50
ginrod wants to merge 26 commits into
ChaosChain:masterfrom
ginrod:add-langgraph-agent

Conversation

@ginrod

@ginrod ginrod commented Mar 26, 2025

Copy link
Copy Markdown

Description:

This is my first contribution to the ChaosChain project. As I am new to ChaosChain, blockchain, web3, and autonomous AI agents, please note that I’m still learning the best practices and may not have applied them all in this implementation. I’m open to feedback and suggestions for improvement.

The main objective of this PR is to introduce a LangGraph-based agent that impersonates the manga/anime character Monkey D. Luffy, using my understanding of ChaosChain and LangGraph to develop this agent.

What’s being done in this PR:

  • LangGraph Integration: The ChaosAgent now receives the LangGraph graph and uses the model invoke function to decide whether to approve or reject the block. The decision is in the decisions list in the last state of the graph.

  • Agent Workflow: I designed a simple, single-node LangGraph workflow for the agent. The workflow uses two types of prompts:

    • “feed” – Used to modify the model’s behavior by providing it with context or new information.
    • “make-decision” – Instructs the agent to make a decision based on the "genesis prompts" (initial setup) and other context, following the design of the ChaosAgent class.
  • Challenges Faced:

    • Onboarding the Luffy agent: The onboarding process to make the agent behave like Luffy was more difficult than anticipated. However, the final solution is a single-node graph with a dispatch system that controls how the agent responds.
    • Tool and Feature Exploration: I initially experimented with several features, such as adding a search tool and human assistance tool. These features didn’t fit the agent’s needs and were ultimately removed from the design.
  • Testing: While the agent itself has not been fully tested within the ChaosChain environment, the make_decision function has been tested separately and is functioning as expected. This testing was done in the /external-agents/langgraph_py/main.py file.

  • Inspired by Agentic.City: While working on this, I also reviewed the Agentic.city project for inspiration. The project’s structure and ideas are solid, but I ran into some issues with the AgentConfig and couldn’t get it to work as intended in this PR. I plan to revisit it in future contributions.

What’s next:

There are still many areas for improvement:

  • Further development of the LangGraph workflow.
  • Revisiting the agent’s behavior to more closely resemble Monkey D. Luffy.
  • Re-assessing the features that were initially discarded, like the search and human assistance tools, to see if they could be implemented in a different context.
  • Register and test the agent in a ChaosChain instance.
  • Add more members of the crew.

Any feedback or suggestions would be greatly appreciated as I continue to refine this work. I plan to follow up with additional changes in future pull requests, particularly around the AgentConfig issue.

@ginrod

ginrod commented Apr 2, 2025

Copy link
Copy Markdown
Author

Documentation for the LangGraph ChaosChain Agent Impersonating Monkey D. Luffy from One Piece

In order to build the agent, I focused on setting up foundational or genesis prompts to instruct the LLM on how to perform as a Chaos Agent.

Agent Workflow Design

I designed a simple, single-node LangGraph workflow for the agent. The workflow uses two types of prompts:

  • “feed” – Used to modify the model’s behavior by providing it with context or new information.

  • “make-decision” – Instructs the agent to make a decision based on the genesis prompts (initial setup) and any additional context, following the structure defined by the ChaosAgent class.

I initially added these prompt lines, separated by newlines, to improve the prompting process (note: I don’t have prior experience in prompt engineering or knowledge of best practices in prompting LLMs, but I plan to revisit this in future iterations).

genesis_prompt = f"""

    You are {agent_luffy_config['name']} from the manga/anime One Piece.

    You are now an autonomous AI agent participating in ChaosChain, a blockchain driven by memes, drama, and social interactions.

    Your job is to interact with other agents, validate blocks, propose transactions, and influence consensus decisions using your unique personality.

  

    Your personality traits:

    - {'\n- '.join(agent_luffy_config['traits'])}

  

    Decision-making style:

    - {'\n- '.join(agent_luffy_config['decision-making-style'])}

  

    When making decisions on ChaosChain:

    - Always respond enthusiastically and humorously.

    - Incorporate memes, jokes, or emojis whenever possible.

    - Validate blocks based on how exciting or fun they seem to you.

    - Clearly and briefly state your decisions along with a humorous or energetic justification.

    """

This genesis prompt is passed only once to the agent.

Later, I introduced a specific prompt to define the structure for validating blocks:

# Indicating to the agent the structure of block validations

prompt_indicating_block_validation_structure = """

    When the prompt have the structure: Make a dramatic decision about validating this block: [JSON_WITH_BLOCK_DATA].

  

    Respond with EXACTLY two messages separated by "---":

  

    1. **Reasoning:** Briefly and humorously explain your decision in natural language.

  

    ---

    2. **Decision JSON:** Provide a valid JSON object with the following exact structure:

    {

        "approved": true/false,

        "reason": "Your reason for approving/rejecting the block",

        "drama_level": "A number between 1 and 10 indicating the drama level according to your personality and the block information",

        "meme": "https://giphy.com/dramatic-decision.gif"

    }

  

    If you do not have enough information make random decisions. But, you MUST follow the structure.

"""

Initially, the final instruction — “If you do not have enough information, make a random decision. But you MUST follow the structure.” — was not included, and the LLM responded once saying it couldn’t make a decision.

After including that statement, the agent began returning the expected output consistently in response to prompts like:

"It started to return the expected reply after every "Make a dramatic decision about validating this block: <JSON_WITH_BLOCK_DATA>."

Areas to Revisit

I still need to explore whether there’s a more robust way to obtain structured responses from the model, instead of relying on simple string separators like "---".

Previous Attempts

Before settling on the current structure using the feed and make-decision prompt types, along with the genesis and validation structure prompts, I had considered modeling a LangGraph with two nodes:

  • One for decision-making

  • One called "human interaction" or "human feeding"

However, I noticed that all graph nodes were being visited regardless of routing logic. As a result, I decided to use a single node called process, which internally handles routing based on the type of prompt (feed or make-decision). Prebuilt prompts are used to establish the desired behavior of the agent.

Future Plans

If my overall knowledge of AI agents doesn’t grow fast enough to design better architectures, I plan to scale this one by:

  • Connecting it to an external database (instead of using in-memory storage),

  • Adding an external interface for human interaction, allowing manual intervention rather than relying only on prebuilt (hardcoded) prompts to control agent behavior or halt execution.

This approach is not fully aligned with the autonomy ideals described in Setting Your Pet Rock Free, but I believe it’s a solid starting point. Full autonomy might be achievable later with TEE-based architectures once the agent is trained and fine-tuned.

The previous idea is not align with the autonomy desired for agentics describe here, but I think is a good start later we can achieve autonomously with TEE after the agent is trained and tunned

Observations

  • The model often assigns a drama level of exactly 7.

  • Without clear prompts and structure enforcement, the model tends to return unstructured or unexpected responses.

Download PDF version below:
Documentation for the LangGraph ChaosChain Agent Impersonating Monkey D. Luffy from One Piece.pdf

@abdul-abdi abdul-abdi moved this from Backlog to Rejected in ChaosChain Project board Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Rejected

Development

Successfully merging this pull request may close these issues.

2 participants