repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | """ |
| #2 | Multi-LLM Research Team with Shared Knowledge Base |
| #3 | |
| #4 | Use Case: AI Research Team where each model has different strengths: |
| #5 | - GPT-4: Technical analysis and code review |
| #6 | - Claude: Writing and documentation |
| #7 | |
| #8 | All models share a common knowledge base, building on each other's work. |
| #9 | Example: GPT-4 analyzes a tech stack → Claude writes documentation → |
| #10 | Data analyst analyzes user data → All models can reference previous research. |
| #11 | """ |
| #12 | |
| #13 | import logging |
| #14 | |
| #15 | from dotenv import load_dotenv |
| #16 | from litellm import completion |
| #17 | |
| #18 | from mem0 import MemoryClient |
| #19 | |
| #20 | load_dotenv() |
| #21 | |
| #22 | # Configure logging |
| #23 | logging.basicConfig( |
| #24 | level=logging.INFO, |
| #25 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", |
| #26 | handlers=[logging.StreamHandler(), logging.FileHandler("research_team.log")], |
| #27 | ) |
| #28 | logger = logging.getLogger(__name__) |
| #29 | |
| #30 | |
| #31 | # Initialize memory client (platform version) |
| #32 | memory = MemoryClient() |
| #33 | |
| #34 | # Research team models with specialized roles |
| #35 | RESEARCH_TEAM = { |
| #36 | "tech_analyst": { |
| #37 | "model": "gpt-4.1-nano-2025-04-14", |
| #38 | "role": "Technical Analyst - Code review, architecture, and technical decisions", |
| #39 | }, |
| #40 | "writer": { |
| #41 | "model": "claude-3-5-sonnet-20241022", |
| #42 | "role": "Documentation Writer - Clear explanations and user guides", |
| #43 | }, |
| #44 | "data_analyst": { |
| #45 | "model": "gpt-4.1-nano-2025-04-14", |
| #46 | "role": "Data Analyst - Insights, trends, and data-driven recommendations", |
| #47 | }, |
| #48 | } |
| #49 | |
| #50 | |
| #51 | def get_team_knowledge(topic: str, project_id: str) -> str: |
| #52 | """Get relevant research from the team's shared knowledge base""" |
| #53 | memories = memory.search(query=topic, user_id=project_id, limit=5) |
| #54 | |
| #55 | if memories: |
| #56 | knowledge = "Team Knowledge Base:\n" |
| #57 | for mem in memories: |
| #58 | if "memory" in mem: |
| #59 | # Get metadata to show which team member contributed |
| #60 | metadata = mem.get("metadata", {}) |
| #61 | contributor = metadata.get("contributor", "Unknown") |
| #62 | knowledge += f"• [{contributor}] {mem['memory']}\n" |
| #63 | return knowledge |
| #64 | return "Team Knowledge Base: Empty - starting fresh research" |
| #65 | |
| #66 | |
| #67 | def research_with_specialist(task: str, specialist: str, project_id: str) -> str: |
| #68 | """Assign research task to specialist with access to team knowledge""" |
| #69 | |
| #70 | if specialist not in RESEARCH_TEAM: |
| #71 | return f"Unknown specialist. Available: {list(RESEARCH_TEAM.keys())}" |
| #72 | |
| #73 | # Get team's accumulated knowledge |
| #74 | team_knowledge = get_team_knowledge(task, project_id) |
| #75 | |
| #76 | # Specialist role and model |
| #77 | spec_info = RESEARCH_TEAM[specialist] |
| #78 | |
| #79 | system_prompt = f"""You are the {spec_info['role']}. |
| #80 | |
| #81 | {team_knowledge} |
| #82 | |
| #83 | Build upon the team's existing research. Reference previous findings when relevant. |
| #84 | Provide actionable insights in your area of expertise.""" |
| #85 | |
| #86 | # Call the specialist's model |
| #87 | response = completion( |
| #88 | model=spec_info["model"], |
| #89 | messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": task}], |
| #90 | ) |
| #91 | |
| #92 | result = response.choices[0].message.content |
| #93 | |
| #94 | # Store research in shared knowledge base using both user_id and agent_id |
| #95 | research_entry = [{"role": "user", "content": f"Task: {task}"}, {"role": "assistant", "content": result}] |
| #96 | |
| #97 | memory.add( |
| #98 | research_entry, |
| #99 | user_id=project_id, # Project-level memory |
| #100 | agent_id=specialist, # Agent-specific memory |
| #101 | metadata={"contributor": specialist, "task_type": "research", "model_used": spec_info["model"]}, |
| #102 | ) |
| #103 | |
| #104 | return result |
| #105 | |
| #106 | |
| #107 | def show_team_knowledge(project_id: str): |
| #108 | """Display the team's accumulated research""" |
| #109 | memories = memory.get_all(user_id=project_id) |
| #110 | |
| #111 | if not memories: |
| #112 | logger.info("No research found for this project") |
| #113 | return |
| #114 | |
| #115 | logger.info(f"Team Research Summary (Project: {project_id}):") |
| #116 | |
| #117 | # Group by contributor |
| #118 | by_contributor = {} |
| #119 | for mem in memories: |
| #120 | if "metadata" in mem and mem["metadata"]: |
| #121 | contributor = mem["metadata"].get("contributor", "Unknown") |
| #122 | if contributor not in by_contributor: |
| #123 | by_contributor[contributor] = [] |
| #124 | by_contributor[contributor].append(mem.get("memory", "")) |
| #125 | |
| #126 | for contributor, research_items in by_contributor.items(): |
| #127 | logger.info(f"{contributor.upper()}:") |
| #128 | for i, item in enumerate(research_items[:3], 1): # Show latest 3 |
| #129 | logger.info(f" {i}. {item[:100]}...") |
| #130 | |
| #131 | |
| #132 | def demo_research_team(): |
| #133 | """Demo: Building a SaaS product with the research team""" |
| #134 | |
| #135 | project = "saas_product_research" |
| #136 | |
| #137 | # Define research pipeline |
| #138 | research_pipeline = [ |
| #139 | { |
| #140 | "stage": "Technical Architecture", |
| #141 | "specialist": "tech_analyst", |
| #142 | "task": "Analyze the best tech stack for a multi-tenant SaaS platform handling 10k+ users. Consider scalability, cost, and development speed.", |
| #143 | }, |
| #144 | { |
| #145 | "stage": "Product Documentation", |
| #146 | "specialist": "writer", |
| #147 | "task": "Based on the technical analysis, write a clear product overview and user onboarding guide for our SaaS platform.", |
| #148 | }, |
| #149 | { |
| #150 | "stage": "Market Analysis", |
| #151 | "specialist": "data_analyst", |
| #152 | "task": "Analyze market trends and pricing strategies for our SaaS platform. What metrics should we track?", |
| #153 | }, |
| #154 | { |
| #155 | "stage": "Strategic Decision", |
| #156 | "specialist": "tech_analyst", |
| #157 | "task": "Given our technical architecture, documentation, and market analysis - what should be our MVP feature priority?", |
| #158 | }, |
| #159 | ] |
| #160 | |
| #161 | logger.info("AI Research Team: Building a SaaS Product") |
| #162 | |
| #163 | # Execute research pipeline |
| #164 | for i, step in enumerate(research_pipeline, 1): |
| #165 | logger.info(f"\nStage {i}: {step['stage']}") |
| #166 | logger.info(f"Specialist: {step['specialist']}") |
| #167 | |
| #168 | result = research_with_specialist(step["task"], step["specialist"], project) |
| #169 | logger.info(f"Task: {step['task']}") |
| #170 | logger.info(f"Result: {result[:200]}...\n") |
| #171 | |
| #172 | show_team_knowledge(project) |
| #173 | |
| #174 | |
| #175 | if __name__ == "__main__": |
| #176 | logger.info("Multi-LLM Research Team") |
| #177 | demo_research_team() |
| #178 |