Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      From Data To Decisions: UX Strategies For Real-Time Dashboards

      September 13, 2025

      Honeycomb launches AI observability suite for developers

      September 13, 2025

      Low-Code vs No-Code Platforms for Node.js: What CTOs Must Know Before Investing

      September 12, 2025

      ServiceNow unveils Zurich AI platform

      September 12, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 2025

      Distribution Release: Q4OS 6.1

      September 12, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Optimizely Mission Control – Part III

      September 14, 2025
      Recent

      Optimizely Mission Control – Part III

      September 14, 2025

      Learning from PHP Log to File Example

      September 13, 2025

      Online EMI Calculator using PHP – Calculate Loan EMI, Interest, and Amortization Schedule

      September 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      sudo vs sudo-rs: What You Need to Know About the Rust Takeover of Classic Sudo Command

      September 14, 2025
      Recent

      sudo vs sudo-rs: What You Need to Know About the Rust Takeover of Classic Sudo Command

      September 14, 2025

      Dmitry — The Deep Magic

      September 13, 2025

      Right way to record and share our Terminal sessions

      September 13, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Machine Learning»Building a Multi-Node Graph-Based AI Agent Framework for Complex Task Automation

    Building a Multi-Node Graph-Based AI Agent Framework for Complex Task Automation

    July 27, 2025

    In this tutorial, we guide you through the development of an advanced Graph Agent framework, powered by the Google Gemini API. Our goal is to build intelligent, multi-step agents that execute tasks through a well-defined graph structure of interconnected nodes. Each node represents a specific function, ranging from taking input, performing logical processing, making decisions, and producing outputs. We use Python, NetworkX for graph modeling, and matplotlib for visualization. By the end, we implement and run two complete examples, a Research Assistant and a Problem Solver, to demonstrate how the framework can efficiently handle complex reasoning workflows.

    Copy CodeCopiedUse a different Browser
    !pip install -q google-generativeai networkx matplotlib
    
    
    import google.generativeai as genai
    import networkx as nx
    import matplotlib.pyplot as plt
    from typing import Dict, List, Any, Callable
    import json
    import asyncio
    from dataclasses import dataclass
    from enum import Enum
    
    
    API_KEY = "use your API key here"
    genai.configure(api_key=API_KEY)
    

    We begin by installing the necessary libraries, google-generativeai, networkx, and matplotlib, to support our graph-based agent framework. After importing essential modules, we configure the Gemini API using our API key to enable powerful content generation capabilities within our agent system.

    Check out the Codes. 

    Copy CodeCopiedUse a different Browser
    class NodeType(Enum):
        INPUT = "input"
        PROCESS = "process"
        DECISION = "decision"
        OUTPUT = "output"
    
    
    @dataclass
    class AgentNode:
        id: str
        type: NodeType
        prompt: str
        function: Callable = None
        dependencies: List[str] = None

    We define a NodeType enumeration to classify different kinds of agent nodes: input, process, decision, and output. Then, using a dataclass AgentNode, we structure each node with an ID, type, prompt, optional function, and a list of dependencies, allowing us to build a modular and flexible agent graph.

    Copy CodeCopiedUse a different Browser
    def create_research_agent():
        agent = GraphAgent()
       
        # Input node
        agent.add_node(AgentNode(
            id="topic_input",
            type=NodeType.INPUT,
            prompt="Research topic input"
        ))
       
        agent.add_node(AgentNode(
            id="research_plan",
            type=NodeType.PROCESS,
            prompt="Create a comprehensive research plan for the topic. Include 3-5 key research questions and methodology.",
            dependencies=["topic_input"]
        ))
       
        agent.add_node(AgentNode(
            id="literature_review",
            type=NodeType.PROCESS,
            prompt="Conduct a thorough literature review. Identify key papers, theories, and current gaps in knowledge.",
            dependencies=["research_plan"]
        ))
       
        agent.add_node(AgentNode(
            id="analysis",
            type=NodeType.PROCESS,
            prompt="Analyze the research findings. Identify patterns, contradictions, and novel insights.",
            dependencies=["literature_review"]
        ))
       
        agent.add_node(AgentNode(
            id="quality_check",
            type=NodeType.DECISION,
            prompt="Evaluate research quality. Is the analysis comprehensive? Are there missing perspectives? Return 'APPROVED' or 'NEEDS_REVISION' with reasons.",
            dependencies=["analysis"]
        ))
       
        agent.add_node(AgentNode(
            id="final_report",
            type=NodeType.OUTPUT,
            prompt="Generate a comprehensive research report with executive summary, key findings, and recommendations.",
            dependencies=["quality_check"]
        ))
       
        return agent

    We create a research agent by sequentially adding specialized nodes to the graph. Starting with a topic input, we define a process flow that includes planning, literature review, and analysis. The agent then makes a quality decision based on the study and finally generates a comprehensive research report, capturing the full lifecycle of a structured research workflow.

    Check out the Codes. 

    Copy CodeCopiedUse a different Browser
    def create_problem_solver():
        agent = GraphAgent()
       
        agent.add_node(AgentNode(
            id="problem_input",
            type=NodeType.INPUT,
            prompt="Problem statement"
        ))
       
        agent.add_node(AgentNode(
            id="problem_analysis",
            type=NodeType.PROCESS,
            prompt="Break down the problem into components. Identify constraints and requirements.",
            dependencies=["problem_input"]
        ))
       
        agent.add_node(AgentNode(
            id="solution_generation",
            type=NodeType.PROCESS,
            prompt="Generate 3 different solution approaches. For each, explain the methodology and expected outcomes.",
            dependencies=["problem_analysis"]
        ))
       
        agent.add_node(AgentNode(
            id="solution_evaluation",
            type=NodeType.DECISION,
            prompt="Evaluate each solution for feasibility, cost, and effectiveness. Rank them and select the best approach.",
            dependencies=["solution_generation"]
        ))
       
        agent.add_node(AgentNode(
            id="implementation_plan",
            type=NodeType.OUTPUT,
            prompt="Create a detailed implementation plan with timeline, resources, and success metrics.",
            dependencies=["solution_evaluation"]
        ))
       
        return agent

    We build a problem-solving agent by defining a logical sequence of nodes, starting from the reception of the problem statement. The agent analyzes the problem, generates multiple solution approaches, evaluates them based on feasibility and effectiveness, and concludes by producing a structured implementation plan, enabling automated, step-by-step resolution of the problem.

    Check out the Codes. 

    Copy CodeCopiedUse a different Browser
    def run_research_demo():
        """Run the research agent demo"""
        print("<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f680.png" alt="🚀" class="wp-smiley" /> Advanced Graph Agent Framework Demo")
        print("=" * 50)
       
        research_agent = create_research_agent()
        print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f4ca.png" alt="📊" class="wp-smiley" /> Research Agent Graph Structure:")
        research_agent.visualize()
       
        print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f50d.png" alt="🔍" class="wp-smiley" /> Executing Research Task...")
       
        research_agent.results["topic_input"] = "Artificial Intelligence in Healthcare"
       
        execution_order = list(nx.topological_sort(research_agent.graph))
       
        for node_id in execution_order:
            if node_id == "topic_input":
                continue
               
            context = {}
            node = research_agent.nodes[node_id]
           
            if node.dependencies:
                for dep in node.dependencies:
                    context[dep] = research_agent.results.get(dep, "")
           
            prompt = node.prompt
            if context:
                context_str = "n".join([f"{k}: {v}" for k, v in context.items()])
                prompt = f"Context:n{context_str}nnTask: {prompt}"
           
            try:
                response = research_agent.model.generate_content(prompt)
                result = response.text.strip()
                research_agent.results[node_id] = result
                print(f"✓ {node_id}: {result[:100]}...")
            except Exception as e:
                research_agent.results[node_id] = f"Error: {str(e)}"
                print(f"✗ {node_id}: Error - {str(e)}")
       
        print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f4cb.png" alt="📋" class="wp-smiley" /> Research Results:")
        for node_id, result in research_agent.results.items():
            print(f"n{node_id.upper()}:")
            print("-" * 30)
            print(result)
       
        return research_agent.results
    
    
    def run_problem_solver_demo():
        """Run the problem solver demo"""
        print("n" + "=" * 50)
        problem_solver = create_problem_solver()
        print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f6e0.png" alt="🛠" class="wp-smiley" /> Problem Solver Graph Structure:")
        problem_solver.visualize()
       
        print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/2699.png" alt="⚙" class="wp-smiley" /> Executing Problem Solving...")
       
        problem_solver.results["problem_input"] = "How to reduce carbon emissions in urban transportation"
       
        execution_order = list(nx.topological_sort(problem_solver.graph))
       
        for node_id in execution_order:
            if node_id == "problem_input":
                continue
               
            context = {}
            node = problem_solver.nodes[node_id]
           
            if node.dependencies:
                for dep in node.dependencies:
                    context[dep] = problem_solver.results.get(dep, "")
           
            prompt = node.prompt
            if context:
                context_str = "n".join([f"{k}: {v}" for k, v in context.items()])
                prompt = f"Context:n{context_str}nnTask: {prompt}"
           
            try:
                response = problem_solver.model.generate_content(prompt)
                result = response.text.strip()
                problem_solver.results[node_id] = result
                print(f"✓ {node_id}: {result[:100]}...")
            except Exception as e:
                problem_solver.results[node_id] = f"Error: {str(e)}"
                print(f"✗ {node_id}: Error - {str(e)}")
       
        print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f4cb.png" alt="📋" class="wp-smiley" /> Problem Solving Results:")
        for node_id, result in problem_solver.results.items():
            print(f"n{node_id.upper()}:")
            print("-" * 30)
            print(result)
       
        return problem_solver.results
    
    
    print("<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f3af.png" alt="🎯" class="wp-smiley" /> Running Research Agent Demo:")
    research_results = run_research_demo()
    
    
    print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/1f3af.png" alt="🎯" class="wp-smiley" /> Running Problem Solver Demo:")
    problem_results = run_problem_solver_demo()
    
    
    print("n<img src="https://s.w.org/images/core/emoji/16.0.1/72x72/2705.png" alt="✅" class="wp-smiley" /> All demos completed successfully!")

    We conclude the tutorial by running two powerful demo agents, one for research and another for problem-solving. In each case, we visualize the graph structure, initialize the input, and execute the agent node-by-node using a topological order. With Gemini generating contextual responses at every step, we observe how each agent autonomously progresses through planning, analysis, decision-making, and output generation, ultimately showcasing the full potential of our graph-based framework.

    In conclusion, we successfully developed and executed intelligent agents that break down and solve tasks step-by-step, utilizing a graph-driven architecture. We see how each node processes context-dependent prompts, leverages Gemini’s capabilities for content generation, and passes results to subsequent nodes. This modular design enhances flexibility and also allows us to visualize the logic flow clearly.

    Check out the Codes. All credit for this research goes to the researchers of this project. SUBSCRIBE NOW to our AI Newsletter

    The post Building a Multi-Node Graph-Based AI Agent Framework for Complex Task Automation appeared first on MarkTechPost.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleNVIDIA AI Dev Team Releases Llama Nemotron Super v1.5: Setting New Standards in Reasoning and Agentic AI
    Next Article Why Context Matters: Transforming AI Model Evaluation with Contextualized Queries

    Related Posts

    Machine Learning

    How to Evaluate Jailbreak Methods: A Case Study with the StrongREJECT Benchmark

    September 3, 2025
    Machine Learning

    Announcing the new cluster creation experience for Amazon SageMaker HyperPod

    September 3, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Microsoft Brings Teams VDI Optimization to Amazon WorkSpaces

    Operating Systems

    CVE-2025-26481 – Dell PowerScale OneFS Denial of Service Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    From MCP to multi-agents: The top 10 open source AI projects on GitHub right now and why they matter

    News & Updates

    ⚡ Weekly Recap: WhatsApp 0-Day, Docker Bug, Salesforce Breach, Fake CAPTCHAs, Spyware App & More

    Development

    Highlights

    Development

    How to Use Wireshark Filters to Analyze Your Network Traffic

    April 3, 2025

    Wireshark is an open-source tool widely regarded as the gold standard for network packet analysis.…

    JavaScript Weekly: Top Picks for June 6, 2025

    June 6, 2025

    CISA Warns of Consilium Fire Panel Vulnerabilities Allowing Remote Takeover

    June 2, 2025

    CVE-2025-46619 – Couchbase Server File Access Vulnerability

    April 30, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.