Framework Adapters¶
a2p provides ready-to-use adapters for popular AI frameworks.
Available Adapters¶
| Framework | Language | Package | Status |
|---|---|---|---|
| LangChain | TypeScript | @a2p/langchain | ✅ Stable |
| LangChain | Python | a2p-langchain | ✅ Stable |
| OpenAI Assistants | TypeScript | @a2p/openai | ✅ Stable |
| LangGraph | TypeScript | @a2p/langgraph | ✅ Stable |
| CrewAI | Python | a2p-crewai | ✅ Stable |
How Adapters Work¶
Adapters provide native integration with each framework:
graph LR
subgraph "Your Agent"
Framework[AI Framework]
Adapter[a2p Adapter]
end
subgraph "a2p"
Profile[User Profile]
end
Framework --> Adapter
Adapter --> Profile What Adapters Do¶
- Read user context — Fetch profile data for personalization
- Inject into prompts — Add user preferences to system prompts
- Propose memories — Learn from conversations
- Handle consent — Respect user policies
Quick Start¶
Common Patterns¶
Reading User Context¶
All adapters load user preferences:
// Context is automatically loaded
const preferences = memory.getPreferences();
// { language: "en-US", style: "concise" }
Proposing Memories¶
Adapters can propose memories from conversations:
// After a conversation turn
await memory.proposeMemory(
"User prefers detailed explanations for technical topics",
{ category: "a2p:preferences.communication", confidence: 0.8 }
);
Respecting Consent¶
Adapters automatically respect user policies:
// Only returns data the agent is allowed to see
const profile = await memory.loadProfile();
// Health data excluded if denied by policy
Building Custom Adapters¶
If your framework isn't supported, you can build a custom adapter:
import { A2PClient } from '@a2p/sdk';
class MyFrameworkAdapter {
private client: A2PClient;
private userDid: string;
constructor(config: { userDid: string; agentDid: string }) {
this.userDid = config.userDid;
this.client = new A2PClient({ agentDid: config.agentDid });
}
async getContext(): Promise<Record<string, any>> {
const profile = await this.client.getProfile({
userDid: this.userDid,
scopes: ['a2p:preferences']
});
return profile.common.preferences;
}
async learn(content: string, category: string): Promise<void> {
await this.client.proposeMemory({
userDid: this.userDid,
content,
category,
confidence: 0.8
});
}
}
Next Steps¶
- LangChain Adapter — Full LangChain guide
- OpenAI Adapter — OpenAI Assistants guide
- SDK Reference — Build custom adapters