Skip to content

Commit 2cbda28

Browse files
committed
feat: add langchain-ai and assistant-ui skills
1 parent b175c73 commit 2cbda28

File tree

88 files changed

+18073
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+18073
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
name: ag-ui-protocol
3+
description: AG-UI (Agent-User Interaction) protocol reference for building AI agent frontends. Use when implementing AG-UI events (RUN_STARTED, TEXT_MESSAGE_*, TOOL_CALL_*, STATE_*), building agents that communicate with frontends, implementing streaming responses, state management with snapshots/deltas, tool call lifecycles, or debugging AG-UI event flows.
4+
allowed-tools:
5+
- Read
6+
- Grep
7+
- Glob
8+
- Edit
9+
- Bash
10+
---
11+
12+
# AG-UI Protocol
13+
14+
The Agent-User Interaction (AG-UI) Protocol is an open, lightweight, event-based protocol that standardizes how AI agents connect to user-facing applications.
15+
16+
## When to Use This Skill
17+
18+
Use this skill when:
19+
- Implementing AG-UI protocol events in your code
20+
- Building agents that communicate with frontends via AG-UI
21+
- Understanding the event types and their structure
22+
- Implementing state management, tool calls, or message streaming
23+
- Debugging AG-UI event flows
24+
25+
## Documentation
26+
27+
See the `docs/2025-11-27/` directory for complete AG-UI protocol documentation:
28+
29+
- `introduction.md` - Protocol overview and integrations
30+
- `concepts/architecture.md` - Core architecture and design
31+
- `concepts/events.md` - Event types and patterns
32+
- `concepts/messages.md` - Message structure and types
33+
- `concepts/state.md` - State management and synchronization
34+
- `concepts/tools.md` - Tool definitions and lifecycle
35+
- `concepts/agents.md` - Agent implementation
36+
- `concepts/middleware.md` - Middleware patterns
37+
- `concepts/serialization.md` - Event serialization and compaction
38+
- `quickstart/introduction.md` - Getting started guide
39+
- `quickstart/server.md` - Server implementation
40+
- `quickstart/clients.md` - Client implementation
41+
42+
## Quick Reference
43+
44+
### Event Types
45+
46+
```typescript
47+
enum EventType {
48+
// Lifecycle
49+
RUN_STARTED = "RUN_STARTED",
50+
RUN_FINISHED = "RUN_FINISHED",
51+
RUN_ERROR = "RUN_ERROR",
52+
STEP_STARTED = "STEP_STARTED",
53+
STEP_FINISHED = "STEP_FINISHED",
54+
55+
// Text Messages
56+
TEXT_MESSAGE_START = "TEXT_MESSAGE_START",
57+
TEXT_MESSAGE_CONTENT = "TEXT_MESSAGE_CONTENT",
58+
TEXT_MESSAGE_END = "TEXT_MESSAGE_END",
59+
60+
// Tool Calls
61+
TOOL_CALL_START = "TOOL_CALL_START",
62+
TOOL_CALL_ARGS = "TOOL_CALL_ARGS",
63+
TOOL_CALL_END = "TOOL_CALL_END",
64+
65+
// State
66+
STATE_SNAPSHOT = "STATE_SNAPSHOT",
67+
STATE_DELTA = "STATE_DELTA",
68+
MESSAGES_SNAPSHOT = "MESSAGES_SNAPSHOT",
69+
70+
// Custom
71+
RAW = "RAW",
72+
CUSTOM = "CUSTOM",
73+
}
74+
```
75+
76+
### Event Patterns
77+
78+
1. **Start-Content-End**: Streams content incrementally (text, tool arguments)
79+
2. **Snapshot-Delta**: State synchronization using complete snapshots + JSON Patch updates
80+
3. **Lifecycle**: Run monitoring with mandatory start/end events
81+
82+
### Message Roles
83+
84+
- `user` - User messages (text and multimodal)
85+
- `assistant` - AI responses (text and tool calls)
86+
- `system` - Instructions or context
87+
- `tool` - Tool execution results
88+
- `activity` - Progress updates
89+
- `developer` - Internal debugging
90+
91+
### Tool Definition Structure
92+
93+
```typescript
94+
interface Tool {
95+
name: string; // Unique identifier
96+
description: string; // Purpose explanation
97+
parameters: JSONSchema; // Accepted arguments
98+
}
99+
```
100+
101+
### Tool Call Lifecycle
102+
103+
1. `TOOL_CALL_START` - Initiates with unique ID
104+
2. `TOOL_CALL_ARGS` - Streams JSON arguments
105+
3. `TOOL_CALL_END` - Marks completion
106+
107+
### State Synchronization
108+
109+
- **STATE_SNAPSHOT** - Complete state replacement
110+
- **STATE_DELTA** - Incremental JSON Patch (RFC 6902) updates
111+
112+
## Source
113+
114+
Documentation downloaded from: https://github.com/ag-ui-protocol/ag-ui/tree/main/docs
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
# Agents
2+
3+
Agents are the core components in the AG-UI protocol that process requests and generate responses. They establish a standardized way for front-end applications to communicate with AI services through a consistent interface, regardless of the underlying implementation.
4+
5+
## What is an Agent?
6+
7+
In AG-UI, an agent is a class that:
8+
9+
1. Manages conversation state and message history
10+
2. Processes incoming messages and context
11+
3. Generates responses through an event-driven streaming interface
12+
4. Follows a standardized protocol for communication
13+
14+
Agents can be implemented to connect with any AI service:
15+
- Large language models (LLMs) like GPT-4 or Claude
16+
- Custom AI systems
17+
- Retrieval augmented generation (RAG) systems
18+
- Multi-agent systems
19+
20+
## Agent Architecture
21+
22+
All agents extend the `AbstractAgent` class:
23+
24+
```typescript
25+
import { AbstractAgent, RunAgentInput, RunAgent } from "@ag-ui/client"
26+
import { Observable } from "rxjs"
27+
28+
class MyAgent extends AbstractAgent {
29+
run(input: RunAgentInput): RunAgent {
30+
return () => new Observable(observer => {
31+
// Emit events
32+
observer.next({ type: "RUN_STARTED", threadId, runId });
33+
// ... processing ...
34+
observer.next({ type: "RUN_FINISHED", threadId, runId });
35+
observer.complete();
36+
});
37+
}
38+
}
39+
```
40+
41+
### Core Components
42+
43+
1. **Configuration** - Agent ID, thread ID, initial state
44+
2. **Messages** - Conversation history
45+
3. **State** - Structured data persisting across interactions
46+
4. **Events** - Standardized messages for communication
47+
5. **Tools** - Functions for external system interaction
48+
49+
## Agent Types
50+
51+
### AbstractAgent
52+
53+
The base class that all agents extend. Handles core event processing, state management, and message history.
54+
55+
### HttpAgent
56+
57+
Connects to remote AI services via HTTP:
58+
59+
```typescript
60+
import { HttpAgent } from "@ag-ui/client"
61+
62+
const agent = new HttpAgent({
63+
url: "https://your-agent-endpoint.com/agent",
64+
headers: {
65+
Authorization: "Bearer your-api-key"
66+
}
67+
})
68+
```
69+
70+
### Custom Agents
71+
72+
Extend `AbstractAgent` for custom integrations:
73+
74+
```typescript
75+
class CustomAgent extends AbstractAgent {
76+
run(input: RunAgentInput): RunAgent {
77+
// Implement your agent logic
78+
}
79+
}
80+
```
81+
82+
## Basic Implementation
83+
84+
```typescript
85+
import {
86+
AbstractAgent,
87+
RunAgent,
88+
RunAgentInput,
89+
EventType,
90+
BaseEvent
91+
} from "@ag-ui/client"
92+
import { Observable } from "rxjs"
93+
94+
class SimpleAgent extends AbstractAgent {
95+
run(input: RunAgentInput): RunAgent {
96+
const { threadId, runId } = input
97+
98+
return () => new Observable<BaseEvent>(observer => {
99+
// 1. Emit RUN_STARTED
100+
observer.next({
101+
type: EventType.RUN_STARTED,
102+
threadId,
103+
runId
104+
})
105+
106+
// 2. Send a message
107+
const messageId = Date.now().toString()
108+
109+
observer.next({
110+
type: EventType.TEXT_MESSAGE_START,
111+
messageId,
112+
role: "assistant"
113+
})
114+
115+
observer.next({
116+
type: EventType.TEXT_MESSAGE_CONTENT,
117+
messageId,
118+
delta: "Hello, world!"
119+
})
120+
121+
observer.next({
122+
type: EventType.TEXT_MESSAGE_END,
123+
messageId
124+
})
125+
126+
// 3. Emit RUN_FINISHED
127+
observer.next({
128+
type: EventType.RUN_FINISHED,
129+
threadId,
130+
runId
131+
})
132+
133+
observer.complete()
134+
})
135+
}
136+
}
137+
```
138+
139+
## Agent Capabilities
140+
141+
### Interactive Communication
142+
143+
Bi-directional communication through event streams:
144+
- Real-time streaming responses character-by-character
145+
- Immediate feedback loops between user and AI
146+
- Progress indicators for long-running operations
147+
- Structured data exchange in both directions
148+
149+
### Tool Usage
150+
151+
Tools are defined and passed from the frontend:
152+
153+
```typescript
154+
// Tool definition
155+
const confirmAction = {
156+
name: "confirmAction",
157+
description: "Ask the user to confirm an action",
158+
parameters: {
159+
type: "object",
160+
properties: {
161+
action: { type: "string", description: "Action to confirm" }
162+
},
163+
required: ["action"]
164+
}
165+
}
166+
167+
// Pass tools to agent
168+
agent.runAgent({
169+
tools: [confirmAction]
170+
})
171+
```
172+
173+
Tool invocation events:
174+
1. `TOOL_CALL_START` - Beginning of tool call
175+
2. `TOOL_CALL_ARGS` - Streaming arguments
176+
3. `TOOL_CALL_END` - Completion
177+
178+
### State Management
179+
180+
Structured state persists across interactions:
181+
182+
```typescript
183+
// Access state
184+
console.log(agent.state.preferences)
185+
186+
// State updates during runs
187+
agent.runAgent().subscribe(event => {
188+
if (event.type === EventType.STATE_DELTA) {
189+
console.log("New state:", agent.state)
190+
}
191+
})
192+
```
193+
194+
### Multi-Agent Collaboration
195+
196+
- Delegate tasks to specialized agents
197+
- Coordinate workflows across multiple agents
198+
- Transfer state and context between agents
199+
- Maintain consistent frontend experience
200+
201+
### Human-in-the-Loop Workflows
202+
203+
- Request human input on decisions
204+
- Pause and resume execution
205+
- Review and modify outputs before finalization
206+
- Combine AI efficiency with human judgment
207+
208+
### Conversational Memory
209+
210+
```typescript
211+
// Access history
212+
console.log(agent.messages)
213+
214+
// Add messages
215+
agent.messages.push({
216+
id: "msg_123",
217+
role: "user",
218+
content: "Can you explain that?"
219+
})
220+
```
221+
222+
## Agent Configuration
223+
224+
```typescript
225+
interface AgentConfig {
226+
agentId?: string; // Unique identifier
227+
description?: string; // Human-readable description
228+
threadId?: string; // Conversation thread ID
229+
initialMessages?: Message[]; // Starting messages
230+
initialState?: State; // Initial state
231+
}
232+
233+
const agent = new HttpAgent({
234+
agentId: "my-agent-123",
235+
description: "A helpful assistant",
236+
threadId: "thread-456",
237+
initialMessages: [
238+
{ id: "1", role: "system", content: "You are helpful." }
239+
],
240+
initialState: { language: "English" }
241+
})
242+
```
243+
244+
## Using Agents
245+
246+
```typescript
247+
const agent = new HttpAgent({
248+
url: "https://your-agent-endpoint.com/agent"
249+
})
250+
251+
agent.messages = [
252+
{ id: "1", role: "user", content: "Hello!" }
253+
]
254+
255+
agent.runAgent({
256+
runId: "run_123",
257+
tools: [],
258+
context: []
259+
}).subscribe({
260+
next: (event) => {
261+
switch (event.type) {
262+
case EventType.TEXT_MESSAGE_CONTENT:
263+
console.log("Content:", event.delta)
264+
break
265+
}
266+
},
267+
error: (error) => console.error("Error:", error),
268+
complete: () => console.log("Run complete")
269+
})
270+
```
271+
272+
## Source
273+
274+
https://github.com/ag-ui-protocol/ag-ui/blob/main/docs/concepts/agents.mdx

0 commit comments

Comments
 (0)