Skip to content

Commit d9a5560

Browse files
committed
feat: add quickstarts to examples dir
1 parent 108ec8f commit d9a5560

6 files changed

Lines changed: 138 additions & 13 deletions

File tree

examples/quickstart.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Quickstart - Agentic Learning SDK
3+
4+
Get started with persistent memory in 30 seconds.
5+
6+
Prerequisites:
7+
pip install agentic-learning anthropic
8+
export ANTHROPIC_API_KEY="your-api-key"
9+
export LETTA_API_KEY="your-api-key"
10+
11+
Usage:
12+
python3 quickstart.py
13+
"""
14+
15+
from anthropic import Anthropic
16+
from agentic_learning import learning
17+
18+
# Initialize LLM client
19+
client = Anthropic()
20+
21+
def ask_claude(message: str):
22+
"""Send a message to Claude and print the response."""
23+
print(f"User: {message}\n")
24+
25+
# That's it - wrap your API calls to enable persistent memory
26+
with learning(agent="quickstart-demo"):
27+
response = client.messages.create(
28+
model="claude-sonnet-4-20250514",
29+
max_tokens=1024,
30+
messages=[{"role": "user", "content": message}]
31+
)
32+
print(f"Assistant: {response.content[0].text}\n")
33+
34+
# Memory automatically persists across LLM API calls
35+
ask_claude("My name is Alice and I love Python.")
36+
37+
ask_claude("What's my name and favorite language?")

examples/quickstart.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Quickstart - Agentic Learning SDK (TypeScript)
3+
*
4+
* Get started with persistent memory in 30 seconds.
5+
*
6+
* Prerequisites:
7+
* npm install @letta-ai/agentic-learning @anthropic-ai/sdk
8+
* export ANTHROPIC_API_KEY="your-api-key"
9+
* export LETTA_API_KEY="your-api-key"
10+
*
11+
* Usage:
12+
* npx tsx quickstart.ts
13+
*/
14+
15+
import Anthropic from "@anthropic-ai/sdk";
16+
import { withLearning } from "@letta-ai/agentic-learning";
17+
18+
// Initialize LLM client
19+
const client = new Anthropic();
20+
21+
async function askClaude(message: string) {
22+
console.log(`User: ${message}\n`);
23+
24+
// That's it - wrap your API calls to enable persistent memory
25+
await withLearning({ agent: 'quickstart-ts-demo' }, async () => {
26+
const response = await client.messages.create({
27+
model: "claude-sonnet-4-20250514",
28+
max_tokens: 1024,
29+
messages: [{ role: "user", content: message }],
30+
});
31+
32+
const text = response.content[0].type === "text" ? response.content[0].text : "";
33+
console.log(`Assistant: ${text}\n`);
34+
});
35+
}
36+
37+
async function main() {
38+
// Memory automatically persists across LLM API calls
39+
await askClaude("My name is Bob and I love TypeScript.");
40+
41+
await askClaude("What's my name and favorite language?");
42+
}
43+
44+
main();

examples/quickstart_async.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
Quickstart Async - Agentic Learning SDK
3+
4+
Get started with persistent memory in async Python.
5+
6+
Prerequisites:
7+
pip install agentic-learning anthropic
8+
export ANTHROPIC_API_KEY="your-api-key"
9+
export LETTA_API_KEY="your-api-key"
10+
11+
Usage:
12+
python3 quickstart_async.py
13+
"""
14+
15+
import asyncio
16+
from anthropic import AsyncAnthropic
17+
from agentic_learning import learning_async
18+
19+
# Initialize LLM client
20+
client = AsyncAnthropic()
21+
22+
async def ask_claude(message: str):
23+
"""Send a message to Claude and print the response."""
24+
print(f"User: {message}\n")
25+
26+
# That's it - wrap your API calls to enable persistent memory
27+
async with learning_async(agent="quickstart-demo"):
28+
response = await client.messages.create(
29+
model="claude-sonnet-4-20250514",
30+
max_tokens=1024,
31+
messages=[{"role": "user", "content": message}]
32+
)
33+
print(f"Assistant: {response.content[0].text}\n")
34+
35+
async def main():
36+
# Memory automatically persists across LLM API calls
37+
await ask_claude("My name is Alice and I love Python.")
38+
39+
await ask_claude("What's my name and favorite language?")
40+
41+
if __name__ == "__main__":
42+
asyncio.run(main())

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "agentic-learning"
7-
version = "0.2.1"
7+
version = "0.2.2"
88
description = "Drop-in SDK for adding persistent memory and learning to any agent."
99
readme = "../README.md"
1010
requires-python = ">=3.10"

typescript/package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@letta-ai/agentic-learning",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Agentic Learning SDK for TypeScript - Automatic memory integration with Letta",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -67,10 +67,9 @@
6767
"typescript": "^5.3.0"
6868
},
6969
"peerDependencies": {
70-
"@anthropic-ai/sdk": "^0.30.1",
71-
"@google/generative-ai": "^0.21.0",
72-
"claude-agent-sdk": "^0.1.0",
73-
"openai": "^4.104.0"
70+
"@anthropic-ai/sdk": ">=0.30.1",
71+
"@google/generative-ai": ">=0.21.0",
72+
"openai": ">=4.104.0"
7473
},
7574
"peerDependenciesMeta": {
7675
"openai": {
@@ -81,9 +80,6 @@
8180
},
8281
"@google/generative-ai": {
8382
"optional": true
84-
},
85-
"claude-agent-sdk": {
86-
"optional": true
8783
}
8884
},
8985
"engines": {

typescript/src/core.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function getCurrentConfig(): LearningConfig | null {
6262
*/
6363
export function learning(options: {
6464
agent: string;
65-
client: AgenticLearning;
65+
client?: AgenticLearning;
6666
captureOnly?: boolean;
6767
memory?: string[];
6868
model?: string;
@@ -79,9 +79,12 @@ export function learning(options: {
7979
// Save the previous context (for nested contexts)
8080
const previousStore = learningContext.getStore();
8181

82+
// Create default client if not provided
83+
const client = options.client || new (require('./client').AgenticLearning)();
84+
8285
const config: LearningConfig = {
8386
agentName: options.agent,
84-
client: options.client,
87+
client: client,
8588
captureOnly: options.captureOnly || false,
8689
memory: options.memory || [],
8790
model: options.model,
@@ -127,7 +130,7 @@ export function learning(options: {
127130
export async function withLearning<T>(
128131
options: {
129132
agent: string;
130-
client: AgenticLearning;
133+
client?: AgenticLearning;
131134
captureOnly?: boolean;
132135
memory?: string[];
133136
model?: string;
@@ -141,9 +144,12 @@ export async function withLearning<T>(
141144
interceptorsInstalled = true;
142145
}
143146

147+
// Create default client if not provided
148+
const client = options.client || new (require('./client').AgenticLearning)();
149+
144150
const config: LearningConfig = {
145151
agentName: options.agent,
146-
client: options.client,
152+
client: client,
147153
captureOnly: options.captureOnly || false,
148154
memory: options.memory || [],
149155
model: options.model,

0 commit comments

Comments
 (0)