![]() |
Ollama4j
A Java library (wrapper/binding) for Ollama server.
|
Classes | |
| class | AgentSpec |
| class | AgentToolParameter |
Public Member Functions | |
| Agent (String name, Ollama ollamaClient, String model, String customPrompt, List< Tools.Tool > tools) | |
| List< OllamaChatMessage > | interact (String userInput, OllamaChatStreamObserver chatTokenHandler) throws OllamaException |
| void | runInteractive () throws OllamaException |
Static Public Member Functions | |
| static Agent | load (String yamlPathOrResource) |
The Agent class represents an AI assistant capable of interacting with the Ollama API server.
It supports the use of tools (interchangeable code components), persistent chat history, and interactive as well as pre-scripted chat sessions.
load(String) for YAML-based configuration. interact(String, OllamaChatStreamObserver). runInteractive() for an interactive console-based session. Definition at line 40 of file Agent.java.
| io.github.ollama4j.agent.Agent.Agent | ( | String | name, |
| Ollama | ollamaClient, | ||
| String | model, | ||
| String | customPrompt, | ||
| List< Tools.Tool > | tools ) |
Constructs a new Agent.
| name | The agent's given name. |
| ollamaClient | The Ollama API client instance to use. |
| model | The model name to use for chat completion. |
| customPrompt | A custom prompt to prepend to all conversations (may be null). |
| tools | List of available tools for function calling. |
Definition at line 68 of file Agent.java.
| List< OllamaChatMessage > io.github.ollama4j.agent.Agent.interact | ( | String | userInput, |
| OllamaChatStreamObserver | chatTokenHandler ) throws OllamaException |
Conducts a conversational interaction with the agent.
| userInput | the user's question, instruction, or message for the agent. |
| chatTokenHandler | an optional handler for receiving streaming token updates from the model as it generates a reply. Can be null if streaming output is not needed. |
OllamaChatMessage objects representing the complete conversation so far. This includes system, user, assistant, and any tool/function calls/results. | OllamaException | if an error occurs communicating with the Ollama API or running tools. |
Definition at line 162 of file Agent.java.
|
static |
Loads and constructs an Agent from a YAML configuration file (classpath or filesystem).
The YAML should define the agent, the model, and the desired tool functions (using their fully qualified class names for auto-discovery).
| yamlPathOrResource | Path or classpath resource name of the YAML file. |
| RuntimeException | if the YAML cannot be read or agent cannot be constructed. |
Definition at line 92 of file Agent.java.
| void io.github.ollama4j.agent.Agent.runInteractive | ( | ) | throws OllamaException |
Launches an endless interactive console session with the agent, echoing user input and the agent's response using the provided chat model and tools.
Type exit to break the loop and terminate the session.
| OllamaException | if any errors occur talking to the Ollama API. |
Definition at line 219 of file Agent.java.