🤖 AI Agents
Create intelligent agents with built-in LLM support
Note:
In HudHudScript v0.4+, the action keyword is preferred over task. Both are supported for backward compatibility.
Agent Architecture
Agent Definition
Provider, Model, Tasks
→
LLM Provider
OpenAI, Anthropic, Ollama
→
Response
Structured Output
Basic Agent
Create an AI agent in just a few lines:
agent Assistant {
provider: "openai"
model: "gpt-4"
task ask(question) {
return this.call(question)
}
}
// Usage
let answer = Assistant.ask("What is HudHudScript?")
print(answer)
✨ That's it!
No complex configuration, no boilerplate code. Just define and use.
Agent Properties
| Property | Type | Description |
|---|---|---|
provider |
String | LLM provider name (openai, anthropic, ollama) |
model |
String | Model name (gpt-4, claude-3, llama2) |
temperature |
Number | Creativity level (0.0-1.0) |
max_tokens |
Number | Maximum response length |
system_prompt |
String | System instructions for the agent |
Advanced Agent
agent DataAnalyst {
provider: "openai"
model: "gpt-4"
temperature: 0.3
max_tokens: 2000
system_prompt: "You are a data analyst expert."
// Multiple tasks
task analyze(data) {
let prompt = `Analyze this data: ${data}`
return this.call({
prompt: prompt,
temperature: 0.5
})
}
task summarize(text) {
return this.call(`Summarize: ${text}`)
}
task visualize(data) {
return this.call({
prompt: `Create visualization for: ${data}`,
format: "json"
})
}
}
// Usage
let analysis = DataAnalyst.analyze([100, 150, 200])
let summary = DataAnalyst.summarize(analysis)
print(summary)
Agent State
Agents can maintain state across calls:
agent ChatBot {
provider: "openai"
model: "gpt-4"
// State variables
state {
conversation_history: []
user_name: null
context: {}
}
task chat(message) {
// Add to history
this.state.conversation_history.push(message)
// Call LLM with context
let response = this.call({
prompt: message,
context: this.state.conversation_history
})
// Save response
this.state.conversation_history.push(response)
return response
}
task reset() {
this.state.conversation_history = []
}
}
// Multi-turn conversation
ChatBot.chat("Hello!")
ChatBot.chat("What's the weather?")
ChatBot.chat("Thanks!")
💡 State Management
State persists across task calls, enabling context-aware conversations.
HudHudScript vs Traditional
❌ Traditional (Python)
# 50+ lines of code
from langchain import OpenAI
from langchain.chains import LLMChain
llm = OpenAI(
model_name="gpt-4",
temperature=0.7,
max_tokens=1000,
# ... many parameters
)
# Manual state management
conversation = []
def chat(message):
conversation.append(message)
response = llm(message)
conversation.append(response)
return response
# Manual error handling
# Manual token tracking
# No governance
✅ HudHudScript
// 15 lines of code
agent ChatBot {
provider: "openai"
model: "gpt-4"
temperature: 0.7
max_tokens: 1000
state {
conversation: []
}
task chat(msg) {
this.state.conversation.push(msg)
return this.call(msg)
}
}
// Automatic error handling
// Automatic token tracking
// Built-in governance
🚀 70% Less Code
HudHudScript handles complexity automatically, letting you focus on logic.