Documentation Index
Fetch the complete documentation index at: https://docs.agenite.com/llms.txt
Use this file to discover all available pages before exploring further.
The @agenite/pretty-logger package provides a beautiful, structured console logging middleware for Agenite agents. It enhances the development experience by making agent interactions, tool usage, and execution flow easy to follow in the terminal.
What is Pretty Logger?
Pretty Logger is a middleware that intercepts the agent execution flow and produces formatted, colorful terminal output. It helps developers:
- Track agent interactions and tool usage
- Follow the streaming output from LLMs
- Visualize nested agent hierarchies
- Monitor token usage for LLM calls
Key features include:
- Color-coded output for different message types
- Boxed formatting for structured content
- Clear separation between different agents in a workflow
- Nested agent prefix display
- Support for streaming LLM output
- Token usage summary at the end of execution
Installation
npm install @agenite/pretty-logger
Basic usage
To use the Pretty Logger with Agenite agents:
import { Agent } from '@agenite/agent';
import { prettyLogger } from '@agenite/pretty-logger';
import { OllamaProvider } from '@agenite/ollama';
// Create an agent with pretty logging
const agent = new Agent({
name: 'my-agent',
provider: new OllamaProvider({
model: 'llama3',
baseURL: 'http://localhost:11434',
}),
middlewares: [
prettyLogger()
],
// ...other agent configuration
});
// Use the agent as normal
const result = await agent.execute({
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Tell me a joke about programming' },
],
},
],
});
Pretty Logger produces console output with the following formatting:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ค User input
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Tell me a joke about programming โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Agent thinking
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ง Thinking [my-agent]
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ I should come up with a programming joke that's clever but โ
โ accessible. Maybe something about debugging or a play on โ
โ programming terms... โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Agent response
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ก Agent response [my-agent]
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Why do programmers prefer dark mode? โ
โ โ
โ Because light attracts bugs! โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ Tool use: [web_search]
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ { โ
โ "query": "latest programming languages 2024" โ
โ } โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โ
Result: [web_search]
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ { โ
โ "results": [ โ
โ { โ
โ "title": "Top Programming Languages for 2024", โ
โ "url": "https://example.com/languages", โ
โ "snippet": "Python, JavaScript, and Rust continue to..."โ
โ } โ
โ ] โ
โ } โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Token usage summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Token Usage
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Input: 125 tokens โ
โ Output: 87 tokens โ
โ Total: 212 tokens โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Nested agent display
For workflows with multiple nested agents, Pretty Logger shows the hierarchy in the output:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
supervisor> researcher> ๐ง Thinking [researcher]
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ I need to find information about the topic... โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
The prefix indicates the agent hierarchy, with supervisor> researcher> showing that the researcher agent is nested under a supervisor agent.
API reference
prettyLogger
The main function that creates the logging middleware.
function prettyLogger(): AsyncGeneratorMiddleware
import { Agent } from '@agenite/agent';
import { prettyLogger } from '@agenite/pretty-logger';
const agent = new Agent({
// ...
middlewares: [
prettyLogger()
],
});
How it works
The Pretty Logger middleware:
- Intercepts execution events from the agentโs generator
- Formats and displays different message types with appropriate styling
- Tracks agent context to display nested agent relationships
- Manages streaming output for thinking and response text
- Creates structured boxes for input and output data
- Summarizes token usage at the end of execution
Integration with other middleware
Pretty Logger works well with other middleware. Place it early in the middleware chain for best results:
import { Agent } from '@agenite/agent';
import { prettyLogger } from '@agenite/pretty-logger';
import { someOtherMiddleware } from '@agenite/some-other-package';
const agent = new Agent({
// ...
middlewares: [
prettyLogger(),
someOtherMiddleware()
],
});
Example: multi-agent workflow
This example shows how Pretty Logger displays a workflow with multiple agents:
import { Agent } from '@agenite/agent';
import { prettyLogger } from '@agenite/pretty-logger';
import { OpenAIProvider } from '@agenite/openai';
// Create a child agent
const researchAgent = new Agent({
name: 'researcher',
provider: new OpenAIProvider({
model: 'gpt-3.5-turbo',
}),
instructions: 'You research information about topics.'
});
// Create a parent agent that uses the research agent
const supervisorAgent = new Agent({
name: 'supervisor',
provider: new OpenAIProvider({
model: 'gpt-4',
}),
middlewares: [
prettyLogger()
],
tools: [
{
name: 'research',
description: 'Research a topic in depth',
parameters: {
type: 'object',
properties: {
topic: {
type: 'string',
description: 'The topic to research'
}
},
required: ['topic']
},
handler: async ({ topic }) => {
return researchAgent.execute({
messages: [
{
role: 'user',
content: [{ type: 'text', text: `Research the topic: ${topic}` }]
}
]
});
}
}
],
instructions: 'You are a supervisor that delegates research tasks.'
});
// Execute the supervisor agent
const result = await supervisorAgent.execute({
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'I need information about quantum computing.' }
],
},
],
});
In this example, the Pretty Logger will show the hierarchy of agents with appropriate prefixes and format all interactions, including those between the supervisor and researcher agents.
Conclusion
The @agenite/pretty-logger package significantly improves the development experience when working with Agenite agents. By providing clear, structured, and colorful console output, it makes it easier to understand agent behavior, debug issues, and demonstrate agent capabilities.
To see the Pretty Logger in action, check out the examples in the GitHub repository.