An api to create local first human friendly agents in the browser or Nodejs
π Read the documentation
Check the π» examples
An agent is a language model that can take decisions. It can:
- Think: use language model servers to perform inference queries
- Work: manage long running workflows with multiple tasks, using tools
- Remember: use semantic memory to store data
- Interact: perform interactions with the user
| Version | Name | Description | Nodejs | Browser |
|---|---|---|---|---|
| @agent-smith/cli | Terminal client | β | β | |
| @agent-smith/agent | Agent | β | β | |
| @agent-smith/task | Task | β | β | |
| @agent-smith/smem | Semantic memory | β | β | |
| @agent-smith/tfm | Templates for models | β | β |
- Composable: the packages have limited responsibilities and can work together
- Declarative: focus on the business logic by expressing features simply
- Explicit: keep it simple and under user control: no hidden magic
Supported inference servers:
Simple inference query (using the inference plugin):
lm q list the planets of the solar systemQuery a thinking model, use qwq (from the models plugin)::
lm think "solve this math problem: ..." m=qwqCompare images (using the vision plugin):
lm vision img1.jpg img2.jpg "Compare the images"Generate a commit message in a git repository (using the git plugin):
lm commitPlugins for the terminal client are available: terminal client plugins
import { Agent } from "@agent-smith/agent";
import { Lm } from "@locallm/api";
let model;
const serverUrl = "http://localhost:8080/v1"; // Local Llama.cpp
const apiKey = "";
const system = "You are a helpful touristic assistant";
const _prompt = `I am landing in Barcelona in one hour: I plan to reach my hotel and then go for outdoor sport.
How are the conditions in the city?`;
function run_get_current_weather(args) {
console.log("Running the get_current_weather tool with args", args);
return '{ "temp": 20.5, "weather": "rain" }'
}
function run_get_current_traffic(args) {
console.log("Running the get_current_traffic tool with args", args);
return '{ "trafic": "normal" }'
}
const get_current_weather = {
"name": "get_current_weather",
"description": "Get the current weather",
"arguments": {
"location": {
"description": "The city and state, e.g. San Francisco, CA",
"required": true
}
},
execute: run_get_current_weather
};
const get_current_traffic = {
"name": "get_current_traffic",
"description": "Get the current road traffic conditions",
"arguments": {
"location": {
"description": "The city and state, e.g. San Francisco, CA",
"required": true
}
},
execute: run_get_current_traffic
};
async function main() {
const lm = new Lm({
providerType: "openai",
serverUrl: serverUrl,
apiKey: apiKey,
onToken: (t) => process.stdout.write(t),
});
const agent = new Agent(lm);
await agent.run(_prompt,
//inference params
{
model: model ?? "",
temperature: 0.5,
top_k: 40,
top_p: 0.95,
min_p: 0,
max_tokens: 4096,
},
// query options
{
debug: false,
verbose: true,
system: system,
tools: [get_current_weather, get_current_traffic]
});
}
(async () => {
await main();
})();To execute a task using the server http api:
import { useServer } from "@agent-smith/apicli";
const api = useServer({
apiKey: "server_api_key",
onToken: (t) => {
// handle the streamed tokens here
process.stdout.write(t)
}
});
await api.executeTask(
"translate",
"Which is the largest planet of the solar system?",
{ lang: "german" }
)The cli is powered by:
The server is powered by:
