Create a new Agent instance.
Configuration object for the agent
The agent internal structure used for by internal operations to generate the agent data
The agent data : this is the equivalent of the .smyth file content.
Used for by external operations to get the agent data
Access to LLM instances for direct model interactions.
Supported providers and calling patterns:
agent.llm.openai(modelId, params)
- OpenAI modelsagent.llm.anthropic(modelId, params)
- Anthropic models// Direct model access
const gpt4 = agent.llm.openai('gpt-4', { temperature: 0.7 });
const response = await gpt4.prompt("Explain quantum computing");
// Using configuration object
const claude = agent.llm.anthropic({
model: 'claude-3-sonnet',
maxTokens: 1000
});
// Streaming response
const stream = await claude.prompt("Write a poem").stream();
stream.on('data', chunk => console.log(chunk));
Add a skill to the agent, enabling it to perform specific tasks or operations.
Skills extend the agent's capabilities by providing custom functions that can be called during conversations or prompt processing.
A skill can be implemented in two ways:
Optional
settings: TSkillSettings
// Add a data fetching skill
agent.addSkill({
name: "fetch_weather",
description: "Get current weather for a location",
process: async (location) => {
const response = await fetch(`/api/weather?location=${location}`);
return response.json();
}
});
// Add a skill that will be used as an entry point in a workflow
agent.addSkill({
name: "fetch_weather",
description: "Get current weather for a location",
});
// Attach the skill to a workflow
Create a new chat session with the agent.
Chat sessions maintain conversation context and allow for back-and-forth interactions with the agent, preserving message history.
Optional
options: string | ChatOptionsThe options for the chat session if you provide a string it'll be used as the chat ID and persistence will be enabled by default
Optional
id?: stringThe ID of the chat. If not provided, a random ID will be generated.
If provided, it will be used to identify the chat in the storage provider and try to load the previous messages from the storage provider if the chat is not found, a new chat will be created
Optional
persist?: boolean | ILLMContextStoreIf true, the chat will be persisted in the default SRE storage provider : next time you create a chat with the same chat ID and same agent ID, it will load the previous messages from the storage provider
If false, the chat will not be persisted
If a ILLMContextStore is provided, the chat will be persisted in the provided store
Chat instance for interactive conversations
Protected
initExpose the agent as a MCP (Model Context Protocol) server
The MCP server can be started in two ways:
The transport for the MCP server
The port for the MCP server (when using SSE transport)
MCP instance
Send a prompt to the agent and get a response.
The returned command can be executed in multiple ways:
await agent.prompt("question")
- returns final resultawait agent.prompt("question").run()
- same as aboveawait agent.prompt("question").stream()
- returns event emitterThe message or question to send to the agent
Optional
options: anyAgentCommand that can be executed or streamed
// Simple prompt (promise mode)
const answer = await agent.prompt("What is the capital of France?");
// Streaming for long responses
const stream = await agent.prompt("Write a detailed report").stream();
stream.on('data', chunk => console.log(chunk));
stream.on('end', () => console.log('Complete!'));
Static
importImport an agent from a file or configuration object.
Supported import patterns:
.smyth
file: Agent.import('/path/to/agent.smyth')
Agent.import(settingsObject)
Agent.import('/path/to/agent.smyth', overrides)
File path or agent settings object
New Agent instance
// Import from file
const agent1 = Agent.import('./my-agent.smyth');
// Import from configuration object
const agent2 = Agent.import({
name: "Imported Agent",
model: "gpt-4"
});
// Import with overrides
const agent3 = Agent.import('./base-agent.smyth', {
name: "Customized Agent",
behavior: "Custom behavior override"
});
Import an agent from a file or configuration object.
Supported import patterns:
.smyth
file: Agent.import('/path/to/agent.smyth')
Agent.import(settingsObject)
Agent.import('/path/to/agent.smyth', overrides)
File path or agent settings object
Optional
overrides: anyOptional settings to override imported configuration
New Agent instance
// Import from file
const agent1 = Agent.import('./my-agent.smyth');
// Import from configuration object
const agent2 = Agent.import({
name: "Imported Agent",
model: "gpt-4"
});
// Import with overrides
const agent3 = Agent.import('./base-agent.smyth', {
name: "Customized Agent",
behavior: "Custom behavior override"
});
The core Agent class for creating and managing AI agents.
An Agent combines models, skills, and behaviors to create intelligent assistants that can process prompts, maintain conversations, and execute tasks.
Example