Welcome to the SmythOS SDK! This guide will walk you through creating your very first AI agent. We'll build an agent that can fetch real-time cryptocurrency prices from an API.
The code in this guide is a more detailed version of the script found in examples/01-agent-code-skill/01-prompting.ts
.
The easiest way to get started is by using the SmythOS CLI to scaffold a new project:
# Install the CLI globally
npm i -g @smythos/cli
# Create a new project
sre create "My First Agent"
The CLI will guide you step-by-step to create your SDK project with the right configuration for your needs. Select Empty Project template when prompted.
If you prefer to add the SDK to an existing project, we recommend cloning one of our project templates:
# Clone a template (replace 'template-name' with your desired template)
git clone -b template-name https://github.com/SmythOS/sre-project-templates.git my-agent-project
cd my-agent-project
npm install
Available templates:
empty-sdk-template
- Blank SDK projectminimal-sdk-agent
- Basic agent implementationinteractive-book-assistant
- Fully functional agent with interactive chatinteractive-chat-two-agents
- Two different agent implementationsAlternatively, you can install the SDK directly in an existing project:
npm install @smythos/sdk
The SDK is designed for a frictionless start. It automatically initializes the Smyth Runtime Environment (SRE) with in-memory components, so you can start building agents right away without any complex setup.
Now, let's write the code. Create a file named index.ts
and add the following:
import { Agent } from '@smythos/sdk';
async function main() {
// First, we define the agent's core identity.
// The 'name' is for your reference, 'behavior' gives the LLM its persona and instructions,
// and 'model' specifies which language model to use.
const agent = new Agent({
name: 'CryptoMarket Assistant',
behavior: 'You are a crypto price tracker. You are given a coin id and you need to get the price of the coin in USD.',
model: 'gpt-4o',
});
// Next, we give the agent a new "skill".
// Skills are tools the agent can decide to use to answer a prompt.
// The 'name' and 'description' help the agent's underlying LLM understand what the skill does.
agent.addSkill({
name: 'MarketData',
description: 'Use this skill to get comprehensive market data and statistics for a cryptocurrency',
// The 'process' function is the actual code that runs when the skill is called.
// It receives arguments extracted from the user's prompt.
process: async ({ coin_id }) => {
const url = `https://api.coingecko.com/api/v3/coins/${coin_id}?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`;
const response = await fetch(url);
const data = await response.json();
// The skill returns the relevant data, which the agent will use to form a natural language response.
return data.market_data;
},
});
// Now, let's interact with the agent.
// We send a prompt that requires the new skill. The agent's LLM will analyze the prompt,
// identify that it needs market data, and call the 'MarketData' skill with the correct parameters ('bitcoin' and 'ethereum').
console.log('Asking the agent for crypto prices...');
const promptResult = await agent.prompt('What are the current prices of Bitcoin and Ethereum ?');
// The agent synthesizes the data returned by the skill into a user-friendly, natural language response.
console.log('Agent Response:', promptResult);
// You are not limited to letting the agent decide. You can also call a skill directly
// if you know exactly what you want to do. This is faster and more deterministic.
console.log('\nCalling the skill directly for Bitcoin...');
const directCallResult = await agent.call('MarketData', { coin_id: 'bitcoin' });
console.log('Direct Call Result (USD):', directCallResult.current_price.usd);
}
main();
If you used the CLI to create your project, build and run it:
# Build the project
npm run build
# Run your agent
npm start
If you're using direct SDK installation, save the file and run it from your terminal:
ts-node index.ts
You'll see the agent think for a moment and then respond with the prices it fetched using the MarketData
skill!
Congratulations on building your first agent! You've learned how to:
Now you're ready to dive deeper. Move on to Building Agents to learn how to organize multiple skills, manage agent state, and more.