Interactive Spring Shell-based command-line interface for the Embabel Agent platform, providing terminal interaction, chat sessions, and agent management commands.
Learn how to create and manage interactive chat sessions with agents.
Start a chat session from the shell:
embabel> chatThe chat session:
Within a chat session:
You: Hello, how can you help?
Agent: I can assist with...
You: /help
# Shows available commands
You: exit
# Ends the sessionWhen redirectLogToFile is enabled, logs are redirected during chat to avoid interfering with the UI:
embabel:
agent:
shell:
redirectLogToFile: trueLogs are written to logs/chat-session.log in your working directory.
Create and run a chat session programmatically:
import com.embabel.agent.shell.TerminalServices
import com.embabel.chat.Chatbot
import com.embabel.chat.ChatSession
import org.springframework.stereotype.Component
@Component
class MyChatService(
private val terminalServices: TerminalServices,
private val chatbot: Chatbot
) {
fun startChat() {
val chatSession = chatbot.createSession()
val result = terminalServices.chat(
chatSession = chatSession,
welcome = "Welcome to my agent chat!",
colorPalette = DefaultColorPalette()
)
println(result) // "Conversation finished"
}
}Provide a custom welcome message:
val result = terminalServices.chat(
chatSession = chatSession,
welcome = """
Welcome to Customer Support Agent!
I can help you with:
- Product information
- Order status
- Technical support
Type 'exit' to end the session.
""".trimIndent()
)Use a themed color palette:
import com.embabel.agent.shell.personality.starwars.StarWarsColorPalette
val result = terminalServices.chat(
chatSession = chatSession,
welcome = "May the Force be with you!",
colorPalette = StarWarsColorPalette()
)The chat method is annotated with @JvmOverloads for Java compatibility:
// Java code
TerminalServices terminalServices = ...;
ChatSession chatSession = ...;
// Use defaults
String result = terminalServices.chat(chatSession);
// With welcome message
String result = terminalServices.chat(chatSession, "Welcome!");
// With all parameters
String result = terminalServices.chat(chatSession, "Welcome!", new StarWarsColorPalette());Manually control log redirection:
import com.embabel.agent.shell.TerminalServices
val terminalServices: TerminalServices = ...
val restoreLogging = terminalServices.redirectLoggingToFile(
filename = "my-chat-session",
dir = System.getProperty("user.dir")
)
try {
// Run chat with logs redirected
terminalServices.chat(chatSession)
} finally {
// Restore original logging
restoreLogging()
}Logs are written to:
{dir}/logs/{filename}.logExample: /Users/me/myapp/logs/my-chat-session.log
The log pattern is:
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%nExample output:
14:23:45.123 [main] INFO c.e.agent.core.AgentPlatform - Processing user message
14:23:45.456 [main] DEBUG c.e.agent.llm.LLMService - Sending prompt to LLM
14:23:46.789 [main] INFO c.e.agent.core.AgentPlatform - Response generatedWhen a session starts:
For each user input:
Session ends when:
If chat session encounters errors:
The chatbot is an optional dependency:
@ShellComponent
class ShellCommands(
// ... other dependencies
@Autowired(required = false)
private val chatbot: Chatbot? = null
)If no Chatbot bean is available:
chat command will not be availableImplement and register a Chatbot bean:
import com.embabel.chat.Chatbot
import com.embabel.chat.ChatSession
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration
class ChatConfiguration {
@Bean
fun chatbot(): Chatbot {
return object : Chatbot {
override fun createSession(): ChatSession {
// Return your chat session implementation
return MyChatSession()
}
}
}
}Combine chat with custom output handling:
import com.embabel.agent.shell.TerminalServices
import com.embabel.agent.api.channel.OutputChannel
@Component
class ChatWithOutputService(
private val terminalServices: TerminalServices,
private val agentPlatform: AgentPlatform,
private val chatbot: Chatbot
) {
fun startChatWithOutput() {
// Create output channel for agent communication
val outputChannel = terminalServices.outputChannel(agentPlatform)
// Create and configure chat session
val chatSession = chatbot.createSession()
// Run chat
terminalServices.chat(
chatSession = chatSession,
welcome = "Chat session with output channel"
)
}
}The output channel handles various event types during chat:
All events are automatically formatted and wrapped according to lineLength configuration.
Chat sessions maintain state across turns:
You: What is the weather in San Francisco?
Agent: The weather in San Francisco is currently 65°F and sunny.
You: What about tomorrow? # Context from previous turn
Agent: Tomorrow in San Francisco will be 68°F with partly cloudy skies.Chat automatically handles interactive elements:
These are handled transparently by the terminal services.
Configure personality for themed chat experience:
embabel:
agent:
logging:
personality: starwarsThe prompt and colors will match the selected personality theme.
If chat command is not available:
Chatbot bean is registeredEnable log redirection:
embabel:
agent:
shell:
redirectLogToFile: trueIf chat session hangs:
If "exit" doesn't work:
tessl i tessl/maven-com-embabel-agent--embabel-agent-shell@0.3.0