Your First BERAgent
Let’s create a Weather Agent to visualize weather data using diagrams. The agent will generate Mermaid-based visualizations. This demonstrates how to create a custom BER agent with specific skills and schema definitions.
Prerequisites
Before starting this tutorial, make sure you have set up your BER development environment following the setup guide
cd ber-os
mkdir agents/my_frist_agent
cd agents/my_first_agent
BERAgent configuration
First, let’s create the agent configuration. This file registers our Weather Agent with BER, defining its name, tag, and available skills. The init()
function ensures the agent is registered when the package is imported.
|
|
Schema configuration
Next, we’ll define the schema for our Weather Agent. This schema specifies the data structure that will be used to store and process weather information. The schema includes fields for location details (filled by the LLM) and weather metrics (populated by the API hook).
The schema uses struct tags to provide JSON mapping and validation rules. The jsonschema
tags define validation rules and field descriptions that will be processed by the LLM to populate values according to the schema requirements. See JSON Schema documentation for more details on validation rules.
|
|
Skill configuration
Now, let’s define the skill configuration for our Weather Agent. This configuration specifies how the skill processes user input, interacts with the LLM, and formats the output. The skill includes:
- A name and description for identification
- A prompt that guides the LLM in extracting location information
- A template for formatting the weather data output
- The schema we defined earlier for data structure
- A hook that fetches real weather data after LLM processing
|
|
Hooks
The fetchWeatherData
hook is responsible for retrieving real-time weather data from the Open-Meteo API using the location coordinates extracted by the LLM. It updates the response schema with current temperature, wind speed, humidity and daylight status.
|
|
Registering the new agent
Register your agent by adding it to agents/registry.go
:
|
|
Test in the TUI:
go run . tui --debug