diff --git a/README.md b/README.md index eb1c4569..e91e7d63 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,14 @@ A comprehensive framework for AI agent experience generation and reuse
Empowering agents to learn from the past and excel in the future

+ --- ## 📰 What's New - **[2025-08]** 🎉 ExperienceMaker v0.1.0 is now available on [PyPI](https://pypi.org/project/experiencemaker/)! - **[2025-07]** 📚 Complete documentation and quick start guides released - **[2025-07]** 🚀 Multi-backend vector store support (Elasticsearch & ChromaDB) + --- ## 📰 What's Next @@ -159,122 +161,289 @@ curl -fsSL https://elastic.co/start-local | sh ## 📝 Your First ExperienceMaker Script Here's how to get started! -- The `load_dotenv()` function loads environment variables from your `.env` file, or you can manually export them. -- The `base_url` points to your ExperienceMaker service. -- The `workspace_id` serves as your experience storage namespace. Experiences in different workspaces remain completely +Note the `workspace_id` serves as your experience storage namespace. Experiences in different workspaces remain completely isolated and cannot access each other. -```python -import requests -from dotenv import load_dotenv - -load_dotenv() -base_url = "http://0.0.0.0:8001/" -workspace_id = "test_workspace" -``` ### 📊 Call Summarizer Examples Batch summarize the trajectory list, where each trajectory consists of a message and a score. - The message is the conversation history. - The score represents the rating between 0 and 1, with 0 typically indicating failure and 1 indicating success. +
+Python + ```python -response = requests.post(url=base_url + "summarizer", json={ - "workspace_id": workspace_id, +import requests + +response = requests.post(url="http://0.0.0.0:8001/summarizer", json={ + "workspace_id": "test_workspace", "traj_list": [ - {"messages": messages, "score": 1.0} + {"messages": [{"role": "user", "content": "hello world"}], "score": 1.0} ] }) -response = response.json() -print(response) - -experience_list = response["experience_list"] +experience_list = response.json()["experience_list"] for experience in experience_list: print(experience) ``` +
+ +
+curl + +```bash +curl -X POST "http://0.0.0.0:8001/summarizer" \ + -H "Content-Type: application/json" \ + -d '{ + "workspace_id": "test_workspace", + "traj_list": [ + { + "messages": [{"role": "user", "content": "hello world"}], + "score": 1.0 + } + ] + }' +``` +
+ +
+Node.js + +```javascript +const fetch = require('node-fetch'); +// or: import fetch from 'node-fetch'; + +async function callSummarizer() { + try { + const response = await fetch('http://0.0.0.0:8001/summarizer', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + workspace_id: "test_workspace", + traj_list: [ + { + messages: [{ role: "user", content: "hello world" }], + score: 1.0 + } + ] + }) + }); + + const data = await response.json(); + const experienceList = data.experience_list; + + experienceList.forEach(experience => { + console.log(experience); + }); + } catch (error) { + console.error('Error:', error); + } +} + +callSummarizer(); +``` +
### 🔍 Call Retriever Examples Retrieve the top_k={top_k} experiences related to {query} in workspace=test_workspace, and finally accept the assembled context. Alternatively, you can also accept the raw experience_list parameter and assemble the context yourself. +
+Python + ```python -response = requests.post(url=base_url + "retriever", json={ - "workspace_id": workspace_id, - "query": query, +import requests + +response = requests.post(url="http://0.0.0.0:8001/retriever", json={ + "workspace_id": "test_workspace", + "query": "what is the meaning of life?", "top_k": 1, }) -response = response.json() -print(response) - -experience_merged: str = response["experience_merged"] +experience_merged: str = response.json()["experience_merged"] print(f"experience_merged={experience_merged}") ``` +
+ +
+curl + +```bash +curl -X POST "http://0.0.0.0:8001/retriever" \ + -H "Content-Type: application/json" \ + -d '{ + "workspace_id": "test_workspace", + "query": "what is the meaning of life?", + "top_k": 1 + }' +``` +
+ +
+Node.js + +```javascript +const fetch = require('node-fetch'); +// or: import fetch from 'node-fetch'; + +async function callRetriever() { + try { + const response = await fetch('http://0.0.0.0:8001/retriever', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + workspace_id: "test_workspace", + query: "what is the meaning of life?", + top_k: 1 + }) + }); + + const data = await response.json(); + const experienceMerged = data.experience_merged; + + console.log(`experience_merged=${experienceMerged}`); + } catch (error) { + console.error('Error:', error); + } +} + +callRetriever(); +``` +
### 💾 Dump Experiences From Vector Store Dump the experience with workspace_id from the vector store into the {path}/{workspace_id}.jsonl file. -
- - -
- -
-```python -def hello_world(): - print("Hello, World!") -``` -
- -
-```java -public class Main { -public static void main(String[] args) { -System.out.println("Hello, World!"); -} -} -``` -
- - - +
+Python ```python -response = requests.post(url=base_url + "vector_store", json={ - "workspace_id": workspace_id, +import requests + +response = requests.post(url="http://0.0.0.0:8001/vector_store", json={ + "workspace_id": "test_workspace", "action": "dump", "path": "./", }) print(response.json()) ``` +
+ +
+curl + +```bash +curl -X POST "http://0.0.0.0:8001/vector_store" \ + -H "Content-Type: application/json" \ + -d '{ + "workspace_id": "test_workspace", + "action": "dump", + "path": "./" + }' +``` +
+ +
+Node.js + +```javascript +const fetch = require('node-fetch'); +// or: import fetch from 'node-fetch'; + +async function dumpExperiences() { + try { + const response = await fetch('http://0.0.0.0:8001/vector_store', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + workspace_id: "test_workspace", + action: "dump", + path: "./" + }) + }); + + const data = await response.json(); + console.log(data); + } catch (error) { + console.error('Error:', error); + } +} + +dumpExperiences(); +``` +
### 📥 Load Experiences To Vector Store Load the {path}/{workspace_id}.jsonl file into the vector store, workspace_id={workspace_id}. +
+Python + ```python -response = requests.post(url=base_url + "vector_store", json={ - "workspace_id": workspace_id, +import requests + +response = requests.post(url="http://0.0.0.0:8001/vector_store", json={ + "workspace_id": "test_workspace", "action": "load", "path": "./", }) print(response.json()) ``` +
+ +
+curl + +```bash +curl -X POST "http://0.0.0.0:8001/vector_store" \ + -H "Content-Type: application/json" \ + -d '{ + "workspace_id": "test_workspace", + "action": "load", + "path": "./" + }' +``` +
+ +
+Node.js + +```javascript +const fetch = require('node-fetch'); +// or: import fetch from 'node-fetch'; + +async function loadExperiences() { + try { + const response = await fetch('http://0.0.0.0:8001/vector_store', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + workspace_id: "test_workspace", + action: "load", + path: "./" + }) + }); + + const data = await response.json(); + console.log(data); + } catch (error) { + console.error('Error:', error); + } +} + +loadExperiences(); +``` +
🎭 **Want to See It in Action?** We've prepared a [simple react agent](./cookbook/simple_demo/simple_demo.py) that demonstrates how to enhance agent capabilities by integrating summarizer and retriever components, achieving significantly better performance.