Guides & Tutorials
Practical guides to help you make the most of AgenticAnts.
Getting Started Guides
Advanced Guides
By Use Case
Customer Support Bots
Monitor conversational AI for customer support:
// Track customer support agent (tracing provider configured once at startup)
const answer = await startActiveObservation('customer-support', async () => {
updateActiveTrace({
name: 'customer-support',
input: customerQuery,
userId: customer.id,
sessionId: ticket.id,
metadata: { channel: 'chat', priority: ticket.priority },
})
// Drafting the reply with an LLM — generations carry model + usageDetails
const gen = startObservation(
'draft-reply',
{ model: 'gpt-4o-mini', input: customerQuery, modelParameters: { temperature: 0.3 } },
{ asType: 'generation' },
)
const result = await agent.process(customerQuery)
gen.update({ output: result, usageDetails: { input: 220, output: 95, total: 315 } })
gen.end()
updateActiveTrace({
output: result,
metadata: { satisfactionScore: feedback.score, resolved: feedback.resolved },
})
return result
}, { asType: 'agent' })
// Track customer support agent (AntsPlatformOtel.configure(...) called once at startup)
String answer = Ants.observe("customer-support", ObservationType.AGENT, agent -> {
agent.updateTrace(TraceAttributes.builder()
.name("customer-support").input(customerQuery)
.userId(customer.id).sessionId(ticket.id)
.metadata(Map.of("channel", "chat", "priority", ticket.priority)).build());
// Drafting the reply with an LLM — generations carry model + usage
AntsGeneration gen = Ants.startGeneration("draft-reply")
.model("gpt-4o-mini").modelParameters(Map.of("temperature", 0.3))
.input(customerQuery);
String result = agent.process(customerQuery);
gen.output(result).usage(220, 95).end();
agent.updateTrace(TraceAttributes.builder().output(result)
.metadata(Map.of("satisfactionScore", feedback.score, "resolved", feedback.resolved)).build());
return result;
});
Content Generation
Monitor content creation agents:
from ants_platform import AntsPlatform
client = AntsPlatform(
public_key=os.environ["ANTS_PLATFORM_PUBLIC_KEY"],
secret_key=os.environ["ANTS_PLATFORM_SECRET_KEY"],
host="https://api.agenticants.ai", # always set host explicitly
)
# Track blog post generation
def generate_blog_post(topic):
with client.start_as_current_observation(
name="content-generation", as_type="agent", agent_name="content-generation"
):
client.update_current_trace(
input=topic,
metadata={"content_type": "blog_post", "target_length": 1500},
)
with client.start_as_current_observation(
name="write-draft", as_type="generation", model="gpt-4o", input=topic
) as gen:
blog_post = run_generation(topic)
gen.update(
output=blog_post,
usage_details={"input": 180, "output": 1420, "total": 1600},
)
with client.start_as_current_observation(
name="quality-check", as_type="tool", input={"draft_len": len(blog_post)}
) as tool:
tool.update(output={
"word_count": len(blog_post.split()),
"readability_score": calculate_readability(blog_post),
"seo_score": analyze_seo(blog_post),
})
client.update_current_trace(output={"blog_post": blog_post})
return blog_post
// Track blog post generation
String generateBlogPost(String topic) {
return Ants.observe("content-generation", ObservationType.AGENT, agent -> {
agent.updateTrace(TraceAttributes.builder().input(topic)
.metadata(Map.of("content_type", "blog_post", "target_length", 1500)).build());
AntsGeneration gen = Ants.startGeneration("write-draft").model("gpt-4o").input(topic);
String blogPost = runGeneration(topic);
gen.output(blogPost).usage(180, 1420).end();
AntsObservation tool = Ants.startObservation("quality-check", ObservationType.TOOL);
tool.input(Map.of("draft_len", blogPost.length())).output(Map.of(
"word_count", blogPost.split("\\s+").length,
"readability_score", calculateReadability(blogPost),
"seo_score", analyzeSeo(blogPost))).end();
agent.updateTrace(TraceAttributes.builder().output(Map.of("blog_post", blogPost)).build());
return blogPost;
});
}
Code Assistants
Monitor AI code generation:
// Track code generation
const generatedCode = await startActiveObservation('code-assistant', async () => {
updateActiveTrace({
name: 'code-assistant',
input: codeRequest,
userId: user.id,
metadata: { language: 'python', complexity: 'medium' },
})
const gen = startObservation(
'generate-code',
{ model: 'gpt-4o', input: codeRequest, modelParameters: { temperature: 0 } },
{ asType: 'generation' },
)
const code = await assistant.generate(codeRequest)
gen.update({ output: code, usageDetails: { input: 310, output: 540, total: 850 } })
gen.end()
// Run the generated code through tests + lint as a tool step
const check = startObservation('quality-check', { input: { linesOfCode: code.split('\n').length } }, { asType: 'tool' })
check.update({ output: { testCoverage: runTests(code), lintErrors: lintCode(code) } })
check.end()
updateActiveTrace({ output: code })
return code
}, { asType: 'agent' })
// Track code generation
String generatedCode = Ants.observe("code-assistant", ObservationType.AGENT, agent -> {
agent.updateTrace(TraceAttributes.builder().input(codeRequest).userId(user.id)
.metadata(Map.of("language", "python", "complexity", "medium")).build());
AntsGeneration gen = Ants.startGeneration("generate-code")
.model("gpt-4o").modelParameters(Map.of("temperature", 0)).input(codeRequest);
String code = assistant.generate(codeRequest);
gen.output(code).usage(310, 540).end();
// Run the generated code through tests + lint as a tool step
AntsObservation check = Ants.startObservation("quality-check", ObservationType.TOOL);
check.input(Map.of("linesOfCode", code.split("\n").length))
.output(Map.of("testCoverage", runTests(code), "lintErrors", lintCode(code))).end();
agent.updateTrace(TraceAttributes.builder().output(code).build());
return code;
});
Data Analysis
Monitor data analysis agents:
from ants_platform import AntsPlatform
client = AntsPlatform(
public_key=os.environ["ANTS_PLATFORM_PUBLIC_KEY"],
secret_key=os.environ["ANTS_PLATFORM_SECRET_KEY"],
host="https://api.agenticants.ai", # always set host explicitly
)
# Track data analysis
def analyze(analysis_request, data):
with client.start_as_current_observation(
name="data-analyst", as_type="agent", agent_name="data-analyst"
):
client.update_current_trace(
input=analysis_request,
metadata={"dataset_size": len(data), "analysis_type": "regression"},
)
with client.start_as_current_observation(
name="run-regression", as_type="tool", input={"rows": len(data)}
) as tool:
results = run_analysis(analysis_request, data)
tool.update(output={
"confidence": results.confidence,
"r_squared": results.r_squared,
"execution_time": results.time,
})
client.update_current_trace(output={"r_squared": results.r_squared})
return results
// Track data analysis
AnalysisResult analyze(String analysisRequest, List<Row> data) {
return Ants.observe("data-analyst", ObservationType.AGENT, agent -> {
agent.updateTrace(TraceAttributes.builder().input(analysisRequest)
.metadata(Map.of("dataset_size", data.size(), "analysis_type", "regression")).build());
AntsObservation tool = Ants.startObservation("run-regression", ObservationType.TOOL);
tool.input(Map.of("rows", data.size()));
AnalysisResult results = runAnalysis(analysisRequest, data);
tool.output(Map.of(
"confidence", results.confidence,
"r_squared", results.rSquared,
"execution_time", results.time)).end();
agent.updateTrace(TraceAttributes.builder().output(Map.of("r_squared", results.rSquared)).build());
return results;
});
}
Integration Guides
LangChain Guide
const handler = new CallbackHandler()
const llm = new ChatOpenAI()
// Pass the handler per-invocation; calls are automatically traced
await llm.invoke('Hello', { callbacks: [handler] })
Full LangChain guide →
AutoGen Guide
AutoGen has no dedicated integration, but you can instrument any agent
function with the @observe() decorator. If your AutoGen agents call OpenAI,
swap the import to the drop-in client so model calls are auto-traced too.
from ants_platform import observe
from ants_platform.openai import openai # drop-in: auto-traces OpenAI calls
@observe(name='autogen-agent')
def run_agent(task):
# AutoGen agent logic; nested OpenAI calls are captured automatically
return agent.run(task)
Full AutoGen guide →
Framework-Specific Guides
- Next.js + AgenticAnts - Monitor Next.js AI features
- FastAPI + AgenticAnts - Python web services
- Streamlit + AgenticAnts - Data apps
- Vercel AI SDK - Edge functions
Common Patterns
Pattern: Request/Response Logging
async function loggedAgent(input: string) {
return startActiveObservation('agent-call', async (span) => {
span.update({ input })
try {
const output = await agent.process(input)
span.update({ output })
return output
} catch (error) {
span.update({
level: 'ERROR',
statusMessage: error.message
})
throw error
}
})
}
Pattern: Multi-Step Workflow
from ants_platform import AntsPlatform
client = AntsPlatform(
public_key=os.environ["ANTS_PLATFORM_PUBLIC_KEY"],
secret_key=os.environ["ANTS_PLATFORM_SECRET_KEY"],
host="https://api.agenticants.ai", # always set host explicitly
)
def multi_step_workflow(query):
with client.start_as_current_observation(
name="workflow", as_type="agent", agent_name="workflow"
):
client.update_current_trace(input=query)
with client.start_as_current_observation(name="step1", as_type="span", input=query) as span:
result1 = step1(query)
span.update(output=result1)
with client.start_as_current_observation(name="step2", as_type="span", input=result1) as span:
result2 = step2(result1)
span.update(output=result2)
client.update_current_trace(output=result2)
return result2
Pattern: Retry Logic
async function withRetry(operation: () => Promise<any>) {
return startActiveObservation('retry-operation', async (span) => {
for (let attempt = 1; attempt <= 3; attempt++) {
try {
const result = await operation()
span.update({
output: result,
metadata: { attempts: attempt }
})
return result
} catch (error) {
if (attempt === 3) {
span.update({
level: 'ERROR',
statusMessage: error.message,
metadata: { attempts: attempt }
})
throw error
}
await new Promise(r => setTimeout(r, 1000 * attempt))
}
}
})
}
Video Tutorials
- Getting Started (5 min) - Quick intro to AgenticAnts
- LangChain Integration (10 min) - Step-by-step setup
- Cost Optimization (15 min) - Reduce AI spending
- Production Deployment (20 min) - Enterprise setup
Browse community-contributed guides:
- Using AgenticAnts with CrewAI by @developer123
- Monitoring Retrieval Quality by @ml_engineer
- Custom Dashboards Tutorial by @data_scientist
Example Projects
Full working examples on GitHub:
- Customer Support Bot - LangChain + OpenAI
- Code Review Agent - Multi-agent with tools
- Document Q&A - RAG with LlamaIndex
- Data Analyst - AutoGen with pandas
View all examples →
Next Steps
Start with a guide that matches your use case: