# Autogen Mastra

> Microsoft AutoGen and Mastra frameworks -- multi-agent conversations, GroupChat, Swarm, TypeScript workflows, RAG, and tool integration patterns.

- Skill: `leolin990405/autogen-mastra` (Agent Skill)
- Install (CLI): `npx get-skill add leolin990405/autogen-mastra`
- Raw SKILL.md: https://api.skillmd.com/api/skills/leolin990405/autogen-mastra/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: LeoLin990405 (https://skillmd.com/u/leolin990405)
- Updated: 2026-11-11
- Page: https://skillmd.com/skills/leolin990405/autogen-mastra

---


# AutoGen & Mastra

## Microsoft AutoGen

### Core Pattern

```python
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient

model = OpenAIChatCompletionClient(model="gpt-4o")

analyst = AssistantAgent("analyst", model_client=model,
    system_message="Analyze code for bugs and performance issues.")

fixer = AssistantAgent("fixer", model_client=model,
    system_message="Fix identified issues with minimal changes.")

reviewer = AssistantAgent("reviewer", model_client=model,
    system_message="Review fixes for correctness. Say APPROVE to finish.")

team = RoundRobinGroupChat(
    [analyst, fixer, reviewer],
    max_turns=10,
)

result = await team.run(task="Review and fix: def add(a,b): return a-b")
```

### Group Chat Types

| Type | Description |
|------|-------------|
| `RoundRobinGroupChat` | Agents take turns in order |
| `SelectorGroupChat` | LLM selects next speaker |
| `Swarm` | Agents hand off to each other |

### SelectorGroupChat
```python
from autogen_agentchat.teams import SelectorGroupChat

team = SelectorGroupChat(
    [analyst, fixer, reviewer],
    model_client=model,
    selector_prompt="Select the next agent based on conversation state.",
)
```

### Tools
```python
from autogen_core import FunctionCall

async def search_code(query: str) -> str:
    """Search codebase for relevant files."""
    return grep_results(query)

agent = AssistantAgent("dev", model_client=model, tools=[search_code])
```

### Streaming
```python
async for message in team.run_stream(task="Fix the authentication bug"):
    print(message)
```

## Mastra (TypeScript)

### Agent Definition
```typescript
import { Agent, createTool } from "@mastra/core";
import { z } from "zod";

const searchTool = createTool({
  id: "search",
  description: "Search documentation",
  inputSchema: z.object({ query: z.string() }),
  execute: async ({ context }) => {
    return { results: await search(context.query) };
  },
});

const agent = new Agent({
  name: "dev-assistant",
  instructions: "You are a helpful development assistant.",
  model: openai("gpt-4o"),
  tools: { search: searchTool },
});

const response = await agent.generate("How do I set up MCP?");
```

### Workflows
```typescript
import { createWorkflow, createStep } from "@mastra/core";

const analyzeStep = createStep({
  id: "analyze",
  inputSchema: z.object({ code: z.string() }),
  execute: async ({ context }) => ({ issues: analyze(context.code) }),
});

const fixStep = createStep({
  id: "fix",
  execute: async ({ context }) => ({ fixed: fix(context.issues) }),
});

const workflow = createWorkflow({ name: "code-review" })
  .then(analyzeStep)
  .then(fixStep);

// Branching
const workflow2 = createWorkflow({ name: "triage" })
  .then(analyzeStep)
  .branch([
    [ctx => ctx.severity === "high", urgentFixStep],
    [ctx => ctx.severity === "low", queueStep],
  ]);

// Parallel
const workflow3 = createWorkflow({ name: "multi-check" })
  .parallel([lintStep, testStep, securityStep]);
```

### RAG Support
```typescript
import { createVectorStore } from "@mastra/core";

const store = createVectorStore({
  provider: "pinecone",
  index: "codebase",
});

const agent = new Agent({
  name: "rag-agent",
  tools: { search: store.asTool() },
});
```

## When to Use

| Framework | Best For |
|-----------|---------|
| AutoGen | Multi-agent conversations, research teams |
| Mastra | TypeScript projects, workflow automation, RAG |

## Sources

- [AutoGen Docs](https://microsoft.github.io/autogen/)
- [Mastra Docs](https://mastra.ai/docs)

