Getting Started
1. Simple Agent
Build your first Liman AI agent step by step
Overview
This guide walks you through creating a Liman AI agent from scratch. You'll start with a simple LLM node and gradually add more features.
Step 1: Environment Setup
Prerequisites
- Python 3.10 or higher
- uv, poetry or pip
Create Your Project
Initialize a Python project
uv init my-liman-agent
cd my-liman-agent
uv venv
source .venv/bin/activate
Install Dependencies
Add Liman dependencies to your project:
uv add liman langchain-openai
Step 2: Create Your First LLM Node
Create Specs Directory
Create a directory for your agent specifications:
mkdir specs
Define Your LLM Node
Create specs/chat.yaml
:
kind: LLMNode
name: chat
prompts:
system:
en: |
You are a helpful assistant.
Always be polite and provide clear answers.
This is the simplest possible LLM node:
- kind: Specifies this is an LLM node
- name: Unique identifier for the node
- prompts.system.en: System prompt in English
Step 3: Create the Agent Application
Create your main application file main.py
:
import asyncio
from langchain_openai.chat_models import ChatOpenAI
from liman.agent import Agent
OPENAI_API_KEY = "" # Replace with your OpenAI API key
async def main():
# Create LangChain LLM model
llm = ChatOpenAI(
api_key=OPENAI_API_KEY,
model="gpt-4o",
)
# Define agent
# args:
# - specs directory
# - start_node: the node to start with
# - llm: LangChain LLM model
agent = Agent("./specs", start_node="LLMNode/chat", llm=llm)
print("Agent ready! Type 'exit' to quit.")
# Simulate chat
while True:
user_input = input("\nYou: ")
if user_input.lower() == "exit":
break
response = await agent.step(user_input)
print(f"Agent: {response}")
if __name__ == "__main__":
asyncio.run(main())
Step 4: Run Your Agent
Run your first agent:
python main.py
# for detailed output, you can enable debug mode:
# LIMAN_DEBUG=1 python main.py
You should see:
Agent ready! Type 'exit' to quit.
You:
Try it out:
You: Hello, how are you?
Agent: Hello! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. How can I assist you today?
You: What's 2+2?
Agent: 2 + 2 is 4.
Next Steps
Congratulations! You've created your first Liman agent. Your project structure now looks like:
chat.yaml
main.py
pyproject.toml (optional)
Try modifying the system prompt in specs/chat.yaml
and restart your agent to see how it changes behavior!
Last updated on