Interactive Spring Shell-based command-line interface for the Embabel Agent platform, providing terminal interaction, chat sessions, and agent management commands.
The shell module provides utility functions for formatting agent process output and converting Markdown to ANSI-styled console output.
import com.embabel.agent.shell.formatProcessOutput
import com.embabel.agent.shell.markdownToConsoleFormats the output of an agent process execution for display in the console.
fun formatProcessOutput(
result: AgentProcessExecution,
colorPalette: ColorPalette,
objectMapper: ObjectMapper,
lineLength: Int
): StringParameters:
result: The AgentProcessExecution result to formatcolorPalette: Color scheme for styling the outputobjectMapper: Jackson ObjectMapper for JSON serializationlineLength: Maximum line length for text wrappingReturns: Formatted string with agent process information, output, cost information, and tool statistics
Behavior:
HasContent: Formats content, checks for Markdown (presence of "#"), applies markdown-to-console conversion if detected, otherwise wraps textInternetResources: Appends list of links with URLs and summariesOutput Format:
|
|{agent process info}
|
|You asked: {basis}
|
|{formatted output}
|
|{cost info}
|{tool statistics}
|Usage:
import com.embabel.agent.shell.formatProcessOutput
import com.embabel.agent.api.common.autonomy.AgentProcessExecution
import com.embabel.agent.spi.logging.ColorPalette
import com.fasterxml.jackson.databind.ObjectMapper
val result: AgentProcessExecution = ... // from execution
val colorPalette: ColorPalette = ... // injected
val objectMapper: ObjectMapper = ... // injected
val lineLength: Int = 140
val formatted = formatProcessOutput(
result = result,
colorPalette = colorPalette,
objectMapper = objectMapper,
lineLength = lineLength
)
println(formatted)Converts Markdown text to ANSI-styled console output with colors and formatting.
fun markdownToConsole(md: String): StringParameters:
md: Markdown text to convertReturns: String with ANSI escape codes for styled console output
Supported Markdown Features:
**text** → Bold text (ANSI code: \u001B[1m)*text* → Italic text (ANSI code: \u001B[3m)__text__ → Underlined text (ANSI code: \u001B[4m)~~text~~ → Strikethrough text (ANSI code: \u001B[9m)> text → Italic, blue, bold text```language\ncode\n``` → Language in italic bold, code in black on gray background`code` → Black text on gray background# text, ## text, etc. → Cyan bold text=): text\n=== → Cyan bold text-): text\n--- → Cyan bold text1. item → Magenta bold number, regular text- item or * item → Magenta bold bullet, regular text[text](url) → Blue text, blue underlined URL in parentheses → Blue alt text, blue underlined URL in parenthesesANSI Color Codes Used:
\u001B[1m\u001B[3m\u001B[4m\u001B[9m\u001B[34m\u001B[35m\u001B[36m\u001B[57;107m\u001B[0m, \u001B[22mUsage:
import com.embabel.agent.shell.markdownToConsole
val markdown = """
# Welcome to the Agent
This agent can:
- **Execute** tasks
- *Analyze* data
- Generate `code`
> Important: Always verify results
Visit [Documentation](https://example.com) for more info.
""".trimIndent()
val styled = markdownToConsole(markdown)
println(styled)Example Input and Output:
Input:
# Agent Report
The agent found **3 results**:
1. Item one
2. Item two
3. Item three
See `agent.log` for details.Output (with ANSI codes):
[Cyan Bold]# Agent Report[Reset]
The agent found [Bold]3 results[Reset]:
[Magenta Bold]1.[Reset] Item one
[Magenta Bold]2.[Reset] Item two
[Magenta Bold]3.[Reset] Item three
See [Black on Gray]agent.log[Reset] for details.Integration with formatProcessOutput:
The formatProcessOutput function automatically uses markdownToConsole when it detects Markdown content (presence of "#" character) in HasContent output:
if (hasContentOutput.content.contains("#")) {
markdownToConsole(hasContentOutput.content)
} else {
hasContentOutput.content
}Regex Patterns Used:
The function uses regex patterns to match Markdown syntax:
\\*\\*(.*?)\\*\\*\\*(.*?)\\*__(.*?)__~~(.*?)~~(> ?.*)([\\d]+\\.|-|\\*) (.*)(?s)\``(\w+)?\n(.*?)\n`````(.*?)`(#{1,6}) (.*?)\\n!?\\[(.*?)]\\((.*?)\\)Attribution:
This function is based on work by Guillaume Laforge (https://glaforge.dev/posts/2025/02/27/pretty-print-markdown-on-the-console/).
Limitations:
tessl i tessl/maven-com-embabel-agent--embabel-agent-shell@0.3.0