#4605 Python Board of Directors for Innovation

#4605 Python Board of Directors for Innovation

#4605 Provide a python app using Ollama supported local models with a board of directors to 1) find opportunities, 2) analyze the opportunity, 3) suggest solutions, and 4) implement solutions using locally implemented agents that support local tool use. Include a critic and response for each step.

Building a "Board of Directors" using local LLMs is a fantastic way to handle complex problem-solving. By using local models via Ollama and a multi-agent framework, you can ensure complete privacy and zero API costs.

For this implementation, we will use AutoGen (specifically the updated autogen-agentchat architecture), as it natively supports local tool calling, structured multi-agent conversations, and strict transition loops (e.g., Director -> Critic -> Director).

Prerequisites

First, ensure you have Ollama running locally with a tool-capable model (like llama3.1 or mistral).

pip install autogen-agentchat autogen-ext-ollama
ollama pull llama3.1

The Python Implementation

Here is a complete, runnable script that sets up a 4-step Board of Directors pipeline with dedicated domain experts, a critic, and a local file-writing tool.

import asyncio
from typing import List
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext_ollama import OllamaChatCompletionClient

# ---------------------------------------------------------
# 1. Define Local Tools
# ---------------------------------------------------------
def save_solution_to_file(filename: str, content: str) -> str:
    """
    Locally implements the solution by writing the final approved plan to a file.
    """
    try:
        with open(filename, "w") as f:
            f.write(content)
        return f"Successfully implemented! Solution saved locally to {filename}."
    except Exception as e:
        return f"Failed to implement: {str(e)}"


async def main():
    # ---------------------------------------------------------
    # 2. Initialize Local Ollama Client
    # ---------------------------------------------------------
    # Using llama3.1 as it has native support for tool calling
    llm_client = OllamaChatCompletionClient(
        model="llama3.1",
        host="http://localhost:11434",
        config={"temperature": 0.2}
    )

    # ---------------------------------------------------------
    # 3. Define the Board Members (Agents)
    # ---------------------------------------------------------
    
    # Step 1: Opportunity Finder
    scout = AssistantAgent(
        name="Opportunity_Scout",
        model_client=llm_client,
        system_message="You are the Head of Growth. Identify one major, high-impact business or operational bottleneck/opportunity in modern tech startups. Be specific."
    )

    # Step 2: Analyst
    analyst = AssistantAgent(
        name="Business_Analyst",
        model_client=llm_client,
        system_message="You are the Chief Financial & Strategy Officer. Analyze the opportunity provided by the Scout. Quantify the risks, costs, and potential ROI."
    )

    # Step 3: Solution Architect
    architect = AssistantAgent(
        name="Solution_Architect",
        model_client=llm_client,
        system_message="You are the CTO. Propose a concrete, step-by-step technological or process-driven solution to capitalize on the analyzed opportunity."
    )

    # Step 4: Executor (with local tool access)
    executor = AssistantAgent(
        name="Implementation_Director",
        model_client=llm_client,
        tools=[save_solution_to_file],
        system_message="You are the COO. Execute the final approved plan. You MUST use the `save_solution_to_file` tool to write the plan into 'final_solution.txt'."
    )

    # The Critic (Evaluates every step)
    critic = AssistantAgent(
        name="Board_Critic",
        model_client=llm_client,
        system_message="You are the Independent Board Chairman. Critically evaluate the proposal or analysis just given. Point out holes, flaws, or missing data. Demand adjustments if necessary."
    )

    # ---------------------------------------------------------
    # 4. Orchestrate the Board Meeting Workflow
    # ---------------------------------------------------------
    # We use a Round Robin format to enforce: Agent -> Critic -> Next Agent
    board_room = RoundRobinGroupChat(
        participants=[scout, critic, analyst, critic, architect, critic, executor],
        termination_condition=MaxMessageTermination(max_messages=7) 
    )

    # ---------------------------------------------------------
    # 5. Run the System
    # ---------------------------------------------------------
    print("💼 The Board of Directors meeting is now in session...\n")
    
    initial_prompt = "Let's begin the quarterly strategy alignment. Scout, what is our biggest opportunity?"
    
    async for message in board_room.run_stream(task=initial_prompt):
        # Format the output beautifully in the terminal
        sender = message.sender
        content = message.content
        
        print(f"=== [{sender.upper()}] ===")
        print(f"{content}\n")

if __name__ == "__main__":
    asyncio.run(main())

How this Architecture Works

  • Ollama Integration: The OllamaChatCompletionClient routes all requests to your localhost. Because we are using llama3.1, it cleanly processes system prompts and tool schemas without needing cloud-based tokens.

  • The Round-Robin Pipeline: The pipeline strictly enforces the "Critic and Response" flow by alternating participants inside the RoundRobinGroupChat:

    1. Opportunity_Scout finds a problem.

    2. Board_Critic tears it apart/refines it.

    3. Business_Analyst analyzes the numbers.

    4. Board_Critic evaluates the financial viability.

    5. Solution_Architect maps out the fix.

    6. Board_Critic ensures the tech stack makes sense.

    7. Implementation_Director calls the local Python tool to finalize it.

  • Local Tool Execution: When the Implementation_Director decides to act, AutoGen safely executes save_solution_to_file entirely on your local machine, creating a final_solution.txt file in your workspace.

What specific domain or industry are you planning to test this Board of Directors against first?


The patter should be like "participants=[scout, critic , scout, ...]," where scout considers the critics input and responds with update. That should occur for each participant.

To achieve that exact rhythm—where each expert presents, the Critic tears it apart, and the expert immediately responds with an updated draft before moving to the next phase—we need to explicitly chain them in that order within the execution flow.

Here is the updated implementation. The participants list is structured so that every single stage follows a strict Expert $\rightarrow$ Critic $\rightarrow$ Expert (Revision) cycle.

Updated Python Implementation

import asyncio
from typing import List
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import MaxMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext_ollama import OllamaChatCompletionClient

# ---------------------------------------------------------
# 1. Define Local Tools
# ---------------------------------------------------------
def save_solution_to_file(filename: str, content: str) -> str:
    """
    Locally implements the solution by writing the final approved plan to a file.
    """
    try:
        with open(filename, "w") as f:
            f.write(content)
        return f"Successfully implemented! Solution saved locally to {filename}."
    except Exception as e:
        return f"Failed to implement: {str(e)}"


async def main():
    # ---------------------------------------------------------
    # 2. Initialize Local Ollama Client
    # ---------------------------------------------------------
    llm_client = OllamaChatCompletionClient(
        model="llama3.1",
        host="http://localhost:11434",
        config={"temperature": 0.3} # Slightly increased for creative revision
    )

    # ---------------------------------------------------------
    # 3. Define the Board Members (Agents)
    # ---------------------------------------------------------
    
    # Step 1: Opportunity Finder
    scout = AssistantAgent(
        name="Opportunity_Scout",
        model_client=llm_client,
        system_message=(
            "You are the Head of Growth. First, identify one high-impact business bottleneck/opportunity. "
            "When the Critic gives feedback, explicitly address their concerns and present an updated, refined opportunity."
        )
    )

    # Step 2: Analyst
    analyst = AssistantAgent(
        name="Business_Analyst",
        model_client=llm_client,
        system_message=(
            "You are the Chief Strategy Officer. Analyze the finalized opportunity. Quantify risks and ROI. "
            "When the Critic gives feedback, adjust your metrics/projections and present a revised financial analysis."
        )
    )

    # Step 3: Solution Architect
    architect = AssistantAgent(
        name="Solution_Architect",
        model_client=llm_client,
        system_message=(
            "You are the CTO. Propose a concrete technological solution for the analyzed opportunity. "
            "When the Critic gives feedback, fix the engineering flaws and present an updated technical solution."
        )
    )

    # Step 4: Executor (with local tool access)
    executor = AssistantAgent(
        name="Implementation_Director",
        model_client=llm_client,
        tools=[save_solution_to_file],
        system_message=(
            "You are the COO. Map out the execution plan. When the Critic reviews your roadmap, "
            "provide your final execution response AND use the `save_solution_to_file` tool to save the absolute final plan to 'final_solution.txt'."
        )
    )

    # The Critic
    critic = AssistantAgent(
        name="Board_Critic",
        model_client=llm_client,
        system_message=(
            "You are the Independent Board Chairman. Critically evaluate the immediately preceding post. "
            "Point out holes, unrealistic timelines, or missing data so the presenter can fix it right away."
        )
    )

    # ---------------------------------------------------------
    # 4. Orchestrate the Board Meeting Workflow (The Custom Pattern)
    # ---------------------------------------------------------
    # We follow the strict: Presenter -> Critic -> Presenter (Revision) pattern for each phase
    flow = [
        # Phase 1: Find Opportunity
        scout, critic, scout,
        
        # Phase 2: Analyze Opportunity
        analyst, critic, analyst,
        
        # Phase 3: Suggest Solution
        architect, critic, architect,
        
        # Phase 4: Implement Solution
        executor, critic, executor
    ]

    board_room = RoundRobinGroupChat(
        participants=flow,
        termination_condition=MaxMessageTermination(max_messages=len(flow)) 
    )

    # ---------------------------------------------------------
    # 5. Run the System
    # ---------------------------------------------------------
    print("💼 The Board of Directors meeting is now in session...\n")
    
    initial_prompt = "Let's begin the alignment. Scout, what is our biggest opportunity?"
    
    async for message in board_room.run_stream(task=initial_prompt):
        sender = message.sender
        content = message.content
        
        print(f"=== [{sender.upper()}] ===")
        print(f"{content}\n")
        print("-" * 40)

if __name__ == "__main__":
    asyncio.run(main())

Why this pattern works optimally here:

  • Immediate Context Retention: Because the scout follows the critic immediately, the local model's context window contains the criticism right at the bottom of its prompt history, making it highly likely to address the specific critiques cleanly.

  • Separation of Concerns: The analyst won't look at the opportunity until the scout and critic have fully hashed out and agreed upon a refined version of it, preventing the analyst from wasting compute on an unvetted premise.


From <https://gemini.google.com/app/85758cf7f6589161>  Google Gemini (Flash 3.5)

Comments

Popular posts from this blog

#3679 Google Gemini 2.5 Pro: Create Python Application to View and Query Neo4j KG

#4054 AI Agents in AI Studio