spinny:~/writing $ less agentic-ai-frameworks-comparison.md
12AI agents اب research demos سے production systems میں منتقل ہو چکے ہیں۔ 2026 تک 60% سے زیادہ enterprise AI applications میں agentic components شامل ہونے کی توقع ہے۔ لیکن agents کو scratch سے بنانا - tool loops، state، memory، error handling، اور multi-agent coordination کا انتظام - پیچیدہ ہے۔ یہاں frameworks کام آتے ہیں۔342026 میں چار frameworks غالب ہیں: **LangGraph**، **CrewAI**، **OpenAI Agents SDK**، اور **Claude Agent SDK**۔ ہر ایک اسی مسئلے کے لیے بنیادی طور پر مختلف نقطہ نظر اپناتا ہے: LLMs کو reason کرنے، plan بنانے، tools استعمال کرنے، اور collaborate کرنے کی صلاحیت دینا۔56## ایک نظر میں78| پہلو | LangGraph | CrewAI | OpenAI Agents SDK | Claude Agent SDK |9|--------|-----------|--------|-------------------|-----------------|10| **بنانے والا** | LangChain | CrewAI Inc. | OpenAI | Anthropic |11| **Architecture** | Graph-based | Role-based | Handoff-based | Autonomous loop |12| **فلسفہ** | زیادہ سے زیادہ کنٹرول | Team collaboration | کم سے کم abstraction | Agent کو computer دو |13| **زبانیں** | Python, TypeScript | Python | Python | Python, TypeScript |14| **Model support** | کوئی بھی (OpenAI, Claude, local) | کوئی بھی | کوئی بھی (نام کے باوجود) | صرف Claude |15| **GitHub stars** | ~29k | ~40k | ~21k | ~6k |16| **بہترین** | Complex stateful workflows | Multi-agent specialization | Routing اور triage | Coding اور file-heavy tasks |1718## LangGraph: The Graph Builder1920LangGraph agent workflows کو **directed cyclic graphs** کے طور پر model کرتا ہے۔ آپ nodes (functions جو کام کرتی ہیں) اور edges (ان کے درمیان transitions، اختیاری طور پر conditional) define کرتے ہیں۔ State graph سے گزرتا ہے اور checkpointing کے ذریعے persist ہوتا ہے۔2122یہ سب سے explicit اور controllable framework ہے - آپ ہر step خود wire کرتے ہیں۔2324```mermaid25graph LR26 Start --> Router[Router Node]27 Router -->|needs research| Research[Research Node]28 Router -->|needs code| Code[Code Node]29 Research --> Synthesize[Synthesize Node]30 Code --> Synthesize31 Synthesize --> End32```3334### بنیادی تصورات3536- **StateGraph**: typed state کے ساتھ graph definition37- **Nodes**: Python functions جو state کو transform کرتی ہیں38- **Edges**: nodes کے درمیان connections، conditional ہو سکتی ہیں39- **Checkpointing**: long-running workflows کے لیے built-in persistence4041### Code Example4243```python44from langgraph.graph import StateGraph, MessagesState, START, END45from langchain_openai import ChatOpenAI4647llm = ChatOpenAI(model="gpt-4o")4849def call_agent(state: MessagesState):50 response = llm.invoke(state["messages"])51 return {"messages": [response]}5253def should_continue(state: MessagesState):54 last = state["messages"][-1]55 if last.tool_calls:56 return "tools"57 return END5859def call_tools(state: MessagesState):60 # Execute tool calls and return results61 results = []62 for tool_call in state["messages"][-1].tool_calls:63 result = execute_tool(tool_call)64 results.append(result)65 return {"messages": results}6667graph = StateGraph(MessagesState)68graph.add_node("agent", call_agent)69graph.add_node("tools", call_tools)70graph.add_edge(START, "agent")71graph.add_conditional_edges("agent", should_continue, {"tools": "tools", END: END})72graph.add_edge("tools", "agent")7374app = graph.compile()75result = app.invoke({"messages": [{"role": "user", "content": "What's the weather?"}]})76```7778### طاقتیں7980- ہر step اور transition پر باریک کنٹرول81- Built-in checkpointing اور human-in-the-loop82- مکمل TypeScript parity83- کسی بھی LLM provider کے ساتھ کام کرتا ہے84- Conditional branching اور loops والی complex workflows کے لیے بہترین8586### کمزوریاں8788- سیکھنے کا curve تیز ہے - آپ کو graph theory concepts سمجھنے ہوں گے89- سادہ use cases کے لیے verbose - ایک basic agent کو دوسرے frameworks سے زیادہ boilerplate چاہیے90- LangSmith کے بغیر graph flows کو debug کرنا مشکل ہو سکتا ہے9192### قیمت9394Open-source (MIT)۔ LangSmith (managed observability platform) میں production monitoring کے لیے paid tiers ہیں۔9596## CrewAI: The Team Assembler9798CrewAI ایک انسانی استعارہ استعمال کرتا ہے: آپ خصوصی agents کی ایک **crew** بناتے ہیں، ہر ایک کی **role**، **goal**، اور **backstory** ہوتی ہے۔ Agents **tools** استعمال کرتے ہوئے **tasks** پر collaborate کرتے ہیں، جنہیں ایک **process** (sequential، hierarchical، یا consensual) coordinate کرتا ہے۔99100اسے ایک team hire کرنے جیسا سمجھیں جہاں ہر رکن کا ایک مخصوص job title اور specialty ہے۔101102```mermaid103graph TD104 Crew[Crew Manager] --> R[Researcher\nRole: Find data\nTools: WebSearch]105 Crew --> W[Writer\nRole: Write content\nTools: FileWrite]106 Crew --> E[Editor\nRole: Review quality\nTools: FileRead]107 R --> Task1[Research Task]108 W --> Task2[Writing Task]109 E --> Task3[Review Task]110 Task1 --> Task2 --> Task3111```112113### بنیادی تصورات114115- **Agent**: role، goal، backstory، اور tools کے ساتھ ایک persona116- **Task**: description، expected output، اور assigned agent کے ساتھ ایک assignment117- **Crew**: ساتھ مل کر کام کرنے والے agents کا گروپ118- **Process**: execution strategy (sequential، hierarchical، consensual)119- **Flow**: متعدد crews کو جوڑنے کے لیے event-driven orchestration layer120121### Code Example122123```python124from crewai import Agent, Task, Crew, Process125126researcher = Agent(127 role="Senior Research Analyst",128 goal="Find comprehensive data about the given topic",129 backstory="You have 10 years of experience in technology research. "130 "You are thorough and always verify facts from multiple sources.",131 tools=[web_search_tool],132 verbose=True,133)134135writer = Agent(136 role="Technical Writer",137 goal="Create clear, engaging technical content",138 backstory="You write for a developer audience. "139 "Your articles are practical and include code examples.",140 tools=[file_tool],141 verbose=True,142)143144research_task = Task(145 description="Research the latest developments in WebAssembly in 2026. "146 "Focus on WASI, Component Model, and production use cases.",147 expected_output="A structured research document with key findings and sources.",148 agent=researcher,149)150151writing_task = Task(152 description="Write a blog post based on the research. "153 "Include code examples and Mermaid diagrams.",154 expected_output="A complete blog post in Markdown format.",155 agent=writer,156 context=[research_task], # Writer receives researcher's output157)158159crew = Crew(160 agents=[researcher, writer],161 tasks=[research_task, writing_task],162 process=Process.sequential,163 verbose=True,164)165166result = crew.kickoff()167print(result.raw)168```169170### طاقتیں171172- بدیہی role-based abstraction - سمجھنے میں آسان173- 100+ built-in tool integrations174- Agents میں shared memory (short-term، long-term، entity)175- سب سے بڑی community (~40k GitHub stars)176- ایک "manager" agent کے ساتھ hierarchical process جو delegate اور validate کرتا ہے177178### کمزوریاں179180- LangGraph کے مقابلے میں کم باریک کنٹرول - آپ roles define کرتے ہیں، exact execution paths نہیں181- جب agents متفق نہ ہوں تو hierarchical process غیر متوقع ہو سکتا ہے182- Multi-agent conversations کو debug کرنا single-agent flows سے مشکل ہے183184### قیمت185186Open-source core (free)۔ CrewAI Platform: $99/month (Teams) سے $120k/year (Enterprise)۔ قیمت live crews اور monthly executions پر مبنی۔187188## OpenAI Agents SDK: The Router189190OpenAI Agents SDK (Swarm کا spiritual successor) **handoffs** پر توجہ دیتا ہے - agents conversations کو دوسرے specialized agents کو transfer کرتے ہیں۔ یہ سب سے minimal framework ہے: agents، tools، handoffs، اور guardrails۔ بس اتنا ہی۔191192```mermaid193graph LR194 User --> Triage[Triage Agent]195 Triage -->|billing question| Billing[Billing Agent]196 Triage -->|refund request| Refund[Refund Agent]197 Triage -->|technical issue| Support[Support Agent]198 Billing --> Response[Response]199 Refund --> Response200 Support --> Response201```202203### بنیادی تصورات204205- **Agent**: model + instructions + tools + handoffs206- **Handoff**: دوسرے agent کو transfer (LLM جو tool call کر سکتا ہے اس طرح modeled)207- **Guardrail**: agent کے ساتھ parallel میں چلنے والا input/output validation208- **Runner**: agent loop کو execute کرتا ہے209- **Tracing**: تمام LLM calls، tool invocations، اور handoffs کے لیے built-in observability210211### Code Example212213```python214from agents import Agent, Runner, handoff, InputGuardrail, GuardrailFunctionOutput215from pydantic import BaseModel216217class SafetyCheck(BaseModel):218 is_safe: bool219 reason: str220221async def content_safety(ctx, agent, input_text):222 result = await Runner.run(223 Agent(name="Safety", instructions="Check if input is safe. No PII."),224 input_text,225 context=ctx,226 )227 output = SafetyCheck.model_validate_json(result.final_output)228 return GuardrailFunctionOutput(229 output_info=output, tripwire_triggered=not output.is_safe230 )231232billing_agent = Agent(233 name="Billing Agent",234 instructions="You handle billing inquiries. Be precise with numbers.",235 tools=[lookup_invoice, process_payment],236)237238refund_agent = Agent(239 name="Refund Agent",240 instructions="You process refund requests. Always verify the order first.",241 tools=[lookup_order, issue_refund],242)243244triage_agent = Agent(245 name="Triage Agent",246 instructions="Route the customer to the right specialist. "247 "Ask clarifying questions if needed.",248 handoffs=[billing_agent, refund_agent],249 input_guardrails=[InputGuardrail(guardrail_function=content_safety)],250)251252result = await Runner.run(triage_agent, "I need a refund for order #4521")253print(result.final_output)254# The triage agent routes to refund_agent, which processes the refund255```256257### طاقتیں258259- Clean handoff pattern - routing/triage workflows کے لیے فطری260- Guardrails execution کے ساتھ parallel میں چلتی ہیں (fail-fast، blocking نہیں)261- Debugging کے لیے built-in tracing dashboard262- نام کے باوجود، non-OpenAI models کو support کرتا ہے263- Minimal abstraction - سمجھنے اور extend کرنے میں آسان264265### کمزوریاں266267- LangGraph کے مقابلے میں کم mature state management268- کوئی built-in persistence یا checkpointing نہیں269- Third-party tools کا ecosystem چھوٹا ہے270- Handoff-centric design ہر architecture کے لیے موزوں نہ ہو271272### قیمت273274Open-source (MIT)۔ آپ جو بھی model استعمال کریں اس کے لیے per-token ادائیگی کریں۔275276## Claude Agent SDK: The Developer277278Claude Agent SDK ایک مختلف نقطہ نظر اپناتا ہے: workflows یا roles define کرنے کی بجائے، آپ agent کو **tools کا ایک set دیتے ہیں اور اسے یہ سمجھنے دیتے ہیں کہ task کیسے مکمل کرنا ہے**۔ یہ وہی autonomous loop استعمال کرتا ہے جو Claude Code کو power کرتا ہے - read، act، verify، iterate۔279280```mermaid281graph TD282 Prompt[User Prompt] --> Loop[Autonomous Agent Loop]283 Loop --> Reason[Reason about next step]284 Reason --> Act[Execute tool]285 Act --> Verify[Check result]286 Verify -->|not done| Loop287 Verify -->|done| Output[Final output]288```289290### بنیادی تصورات291292- **query()**: agent loop شروع کرنے کا main entry point293- **Built-in tools**: Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch294- **MCP کے ذریعے custom tools**: in-process MCP servers کے طور پر tools define کریں295- **Sub-agents**: خصوصی agents جنہیں parent delegate کر سکتا ہے296- **Sessions**: متعدد interactions میں context برقرار رکھیں297298### Code Example299300```typescript301import { tool, createSdkMcpServer, query } from "@anthropic-ai/claude-agent-sdk";302import { z } from "zod";303304const searchDocs = tool(305 "search_docs",306 "Search the internal documentation for relevant information",307 { query: z.string().describe("Search query") },308 async ({ query }) => {309 const results = await vectorStore.similaritySearch(query, 5);310 return {311 content: [{ type: "text", text: results.map(r => r.pageContent).join("\n\n") }],312 };313 }314);315316const docsServer = createSdkMcpServer({317 name: "docs",318 version: "1.0.0",319 tools: [searchDocs],320});321322for await (const message of query({323 prompt: "Find how authentication works in our system and write a summary",324 options: {325 mcpServers: { docs: docsServer },326 allowedTools: ["Read", "Glob", "Grep", "mcp__docs__search_docs"],327 },328})) {329 if (message.type === "result" && message.subtype === "success") {330 console.log(message.result);331 }332}333```334335### طاقتیں336337- First-class MCP integration - کسی بھی MCP server ecosystem سے جڑیں338- File operations، terminal، اور web access کے لیے built-in tools339- بڑے codebases کے لیے automatic context compaction340- Complex tasks کے لیے sub-agent parallelism341- Claude Code جیسا ہی engine - حقیقی development workflows پر battle-tested342343### کمزوریاں344345- صرف Claude models - کوئی multi-provider support نہیں346- چھوٹی community کے ساتھ نیا framework347- Python SDK کے لیے بھی Node.js runtime درکار348- LangGraph کے مقابلے میں کم explicit workflow control349350### قیمت351352Open-source۔ Standard Claude API token rates۔ Managed Agents (hosted version): token costs کے علاوہ $0.08 per session-hour۔353354## کب کون سا چنیں355356```mermaid357graph TD358 Start{What's your priority?}359 Start -->|Full control over workflow| LG[LangGraph]360 Start -->|Multi-agent collaboration| CA[CrewAI]361 Start -->|Routing and triage| OA[OpenAI Agents SDK]362 Start -->|Coding and file automation| CS[Claude Agent SDK]363364 LG --> LGU[Complex stateful workflows\nConditional branching\nHuman-in-the-loop]365 CA --> CAU[Team of specialized agents\nResearch + writing pipelines\nContent generation]366 OA --> OAU[Customer service routing\nMulti-step handoffs\nInput validation]367 CS --> CSU[Code generation and review\nFile-heavy automation\nMCP tool ecosystem]368```369370### LangGraph چنیں اگر:371- آپ کو workflow کے ہر step پر درست کنٹرول چاہیے372- آپ کے use case میں complex conditional logic اور loops شامل ہیں373- آپ کو built-in persistence اور human-in-the-loop checkpoints چاہیے374- آپ کو ایک ہی workflow میں متعدد LLM providers استعمال کرنے ہیں375376### CrewAI چنیں اگر:377- آپ ایک بدیہی، role-based abstraction چاہتے ہیں378- آپ کے task میں مختلف specialties والے متعدد agents شامل ہیں379- آپ کو agents کو collaborate کرنے اور ایک دوسرے کو context pass کرنے کی ضرورت ہے380- آپ سب سے بڑی community اور سب سے زیادہ built-in integrations چاہتے ہیں381382### OpenAI Agents SDK چنیں اگر:383- آپ کا بنیادی pattern conversations کو specialists تک route کرنا ہے384- آپ کو guardrails چاہیے جو parallel میں input/output validate کریں385- آپ کم سے کم boilerplate کے ساتھ سب سے سادہ abstraction چاہتے ہیں386- Built-in tracing اور observability اہم ہیں387388### Claude Agent SDK چنیں اگر:389- آپ کے agents کو code read، write، اور execute کرنا ہے390- آپ first-class MCP server integration چاہتے ہیں391- آپ کو autonomous agents چاہیے جو iterate اور self-correct کریں392- آپ پہلے سے Claude استعمال کر رہے ہیں اور گہرا ترین integration چاہتے ہیں393394## کیا آپ Frameworks کو Combine کر سکتے ہیں؟395396ہاں۔ ایک عام pattern یہ ہے کہ orchestration کے لیے ایک framework اور individual agents کے لیے دوسرا:397398- **LangGraph** مجموعی workflow graph کے لیے399- **CrewAI** ایک مخصوص node کے لیے جس میں multi-agent collaboration چاہیے400- **Claude Agent SDK** MCP کے ذریعے coding-related sub-tasks کے لیے401- **OpenAI Agents SDK** customer-facing triage اور routing کے لیے402403یہ frameworks باہمی طور پر خارج نہیں ہیں۔ اپنے system کے ہر حصے کے لیے جو موزوں ہو وہ استعمال کریں۔404405## نتیجہ406407ہر framework ایک واضح شرط لگاتا ہے:408409- **LangGraph** control کے لیے optimize کرتا ہے - آپ ہر transition طے کرتے ہیں410- **CrewAI** collaboration کے لیے optimize کرتا ہے - agents ایک team کے طور پر کام کرتے ہیں411- **OpenAI Agents SDK** simplicity کے لیے optimize کرتا ہے - minimal abstraction، clean handoffs412- **Claude Agent SDK** autonomy کے لیے optimize کرتا ہے - tools دو اور کام کرنے دو413414صحیح انتخاب آپ کے workflow، آپ کی team، اور آپ کے موجودہ stack پر منحصر ہے۔ وہ چنیں جو آپ کے primary use case سے میل کھاتا ہو، اسے اچھی طرح سیکھیں، اور جب ان کے sweet spot پر پہنچیں تو دوسروں کو شامل کریں۔415
:Agentic AI Frameworks کا موازنہ: LangGraph بمقابلہ CrewAI بمقابلہ OpenAI Agents SDK بمقابلہ Claude Agent SDKlines 1-415 (END) — press q to close