AI Agents i MCP 2024
Model Context Protocol, Vercel AI SDK (streaming), LangGraph (multi-agent) i RAG z pgvector.
6 narzędzi do budowania agentów AI
MCP, Vercel AI SDK, LangGraph, Assistants API, RAG i observability — typ i zastosowanie.
| Narzędzie | Typ | Opis |
|---|---|---|
| Vercel AI SDK | Framework | Streaming, hooks React, multi-provider, tool calling |
| Model Context Protocol | Standard | Universal interface LLM-narzędzia, plug-and-play |
| LangGraph | Orkiestracja | Graf-based agents, multi-agent, human-in-the-loop |
| OpenAI Assistants API | Managed | Thread, Run, Files, Code Interpreter wbudowany |
| RAG + pgvector | Dane | Retrieval Augmented Generation z własną bazą wiedzy |
| LangSmith / Helicone | Observability | Traces, evals, costs monitoring dla LLM apps |
Często zadawane pytania
AI Agents — co to jest i jak działają autonomiczne agenty AI?
AI Agent: system AI zdolny do podejmowania działań. Cel-oriented. Nie tylko generowanie tekstu. Plan + Execute + Observe loop. ReAct pattern: Reasoning + Acting. Agent widzi: Tools (funkcje do wywołania). Memory (historia). Context (zadanie). Cycle: Think (co zrobić) -> Act (wywołaj tool) -> Observe (wynik) -> Think. Typy agentów: Single Agent: jeden LLM + tools. Proste zadania. Multi-Agent: wiele agentów współpracuje. Złożone zadania. Supervisor agent: deleguje do specjalistów. Agentic RAG: retrieval + generation + actions. Narzędzia (Tools): funkcje które agent może wywołać. search_web(query). read_file(path). write_code(spec). send_email(to, body). API calls. Tool definition: name, description, parameters (JSON Schema). LLM decyduje kiedy wywołać. Tool calling (Function Calling): OpenAI, Anthropic, Gemini. Model zwraca tool_call. Aplikacja wywołuje funkcję. Wynik wraca do modelu. Kontynuuje. Przykład: zapytanie: 'Jaka jest pogoda w Warszawie?'. Agent: wywołuje get_weather('Warsaw'). Wynik: {temp: 15, condition: 'cloudy'}. Odpowiedź: 'W Warszawie jest 15 stopni i pochmurno'. Bez agenta: nie wiedziałby (brak internetu). Memory: Short-term: context window. Long-term: vector database, Redis. Episodic: historia interakcji. Semantic: wiedza domenowa.
Model Context Protocol (MCP) — standard dla AI narzędzi?
MCP: Anthropic (2024-11). Standard protokół. LLM komunikuje się z zewnętrznymi systemami. Jak USB dla AI — plug-and-play narzędzia. Problem który rozwiązuje: każda AI aplikacja implementuje własne narzędzia. Brak standaryzacji. Trudna wymienność. MCP = universal interface. Architektura: MCP Host (Claude Desktop, Cursor). MCP Client (wbudowany w host). MCP Server (zewnętrzny serwis). Serwer oferuje: Tools (wywołania). Resources (pliki, dane). Prompts (szablony). MCP Server przykład (TypeScript): import {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'. const server = new McpServer({name: 'weather', version: '1.0'}). server.tool('get_weather', {city: z.string()}, async ({city}) => { const data = await fetchWeather(city). return {content: [{type: 'text', text: JSON.stringify(data)}]} }). Oficjalne MCP Servers: Filesystem, GitHub, Postgres, Slack, Google Drive, Brave Search, Fetch, Memory. Używanie w Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json. mcpServers: {filesystem: {command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', '/path']}}. Claude automatycznie używa. MCP vs Function Calling: Function Calling — aplikacja-specific. MCP — cross-application standard. Claude Desktop, Cursor, Windsurf — wszystkie używają MCP. Open standard: open-source spec. Społeczność buduje serwery. Marketplace: mcp.so.
Vercel AI SDK — budowanie AI aplikacji w Next.js?
Vercel AI SDK: open-source. React hooks + streaming. Multi-provider. Instalacja: npm install ai @ai-sdk/openai. Podstawy: import {generateText, streamText} from 'ai'. import {openai} from '@ai-sdk/openai'. Generowanie: const {text} = await generateText({model: openai('gpt-4o'), prompt: 'Wyjaśnij TypeScript'}). Stream: const result = await streamText({model: openai('gpt-4o'), prompt: 'Napisz opowiadanie'}). for await (const chunk of result.textStream) { process.stdout.write(chunk) }. Chat w Next.js: import {useChat} from 'ai/react'. export default function Chat() { const {messages, input, handleInputChange, handleSubmit} = useChat(). return form onSubmit={handleSubmit} input value={input} onChange={handleInputChange}. }. API route: import {streamText} from 'ai'. export async function POST(req: Request) { const {messages} = await req.json(). const result = await streamText({model: openai('gpt-4o'), messages}). return result.toDataStreamResponse() }. Tool calling z AI SDK: const {text} = await generateText({model: openai('gpt-4o'), tools: {weather: {description: 'Get weather', parameters: z.object({city: z.string()}), execute: async ({city}) => getWeather(city)}}, prompt: 'Pogoda w Warszawie?'}). Providers: @ai-sdk/anthropic. @ai-sdk/google. @ai-sdk/mistral. @ai-sdk/openai. Unified API. Structured output: generateObject() — JSON Schema output. Zod schema. generateText({schema: z.object({name: z.string()})}). useObject hook.
LangGraph i LangChain — orkiestracja agentów AI?
LangChain: framework dla aplikacji LLM. Python i JavaScript. Chains, Agents, RAG. Wiele abstrakcji. Krytyka: zbyt duży, nadmiernie abstrakcyjny. LangGraph: Harrison Chase. Graf-based agent orchestration. Nodes = kroki. Edges = przepływ. State machine dla agentów. Bardziej kontrolowalny. Instalacja: pip install langgraph (Python). npm install @langchain/langgraph (JS). Graf agenta: import {StateGraph, END} from '@langchain/langgraph'. const graph = new StateGraph({channels: {messages: {value: (x, y) => x.concat(y)}, next: null}}). graph.addNode('agent', agentNode). graph.addNode('tools', toolsNode). graph.addEdge('agent', 'tools'). graph.addConditionalEdges('tools', shouldContinue, {continue: 'agent', end: END}). Multi-agent pattern: Supervisor + Specialists. Supervisor router: do który agenta. Code Agent: pisze kod. Research Agent: szuka informacji. Writer Agent: tworzy treść. Human-in-the-loop: graph.addInterrupt() — pauza dla człowieka. Zatwierdzenie akcji. Bezpieczniejszy agent. Memory w LangGraph: MemorySaver — in-memory. PostgresSaver — trwała pamięć. Persist conversation state. Streaming: graph.stream() — każdy krok jako event. Wizualizacja kroków. LangSmith: observability dla LangChain. Traces. Evals. Datasets. Prod monitoring. Alternatywy: CrewAI, AutoGen, LlamaIndex, Haystack.
RAG — Retrieval Augmented Generation i vector databases 2024?
RAG: uzupełnij LLM o własne dane. Nie fine-tuning. Nie hallucination. Przeszukuj dokumenty -> podaj kontekst do LLM. Architektura RAG: Document Ingestion: chunking, embedding, store w vector DB. Query Processing: embed query, search vector DB. Generation: LLM + retrieved context -> odpowiedź. Chunking: RecursiveCharacterTextSplitter — po paragrafach, zdaniach. Chunk size: 512-1024 tokens. Overlap: 50-100 tokens dla kontekstu. Embeddings: OpenAI text-embedding-3-small (szybki, tani). text-embedding-3-large (dokładniejszy). Lokalne: nomic-embed-text, mxbai-embed. Sentence Transformers (Python). Vector Databases: Pinecone — managed, serverless. Qdrant — open-source, Rust. Weaviate — graphQL API, multi-modal. Chroma — local dev, Python. pgvector — PostgreSQL extension. Supabase pgvector — easy. Turso + sqlite-vec — SQLite. Przykład z AI SDK i pgvector: embed document chunks. store z embedding kolumną. embed query. SELECT cosine_similarity. Retrieve top 5 chunks. LLM z kontekstem. Advanced RAG: HyDE: query -> hypothetical document -> embed. Reranking: cross-encoder po retrieval. Multi-query: kilka wariacji pytania. Parent-child chunks: mały chunk find, duży chunk context. Agentic RAG: agent decyduje kiedy szukać. Iterative retrieval. Self-correcting. Evaluation: RAGAS — faithfulness, relevancy, context recall. Trulens — trust metrics.
Powiązane artykuły
Skontaktuj się z nami
Porozmawiajmy o Twoim projekcie. Bezpłatna wycena w ciągu 24 godzin.
Wyślij zapytanie
Telefon
+48 790 814 814
Pon-Pt: 9:00 - 18:00
adam@fotz.pl
Odpowiadamy w ciągu 24h
Adres
Plac Wolności 16
61-739 Poznań
Godziny pracy
Wolisz porozmawiać?
Zadzwoń teraz i porozmawiaj z naszym specjalistą o Twoim projekcie.
Zadzwoń teraz