mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-10-25 14:49:29 +02:00
Enhance agent documentation by refining the definition and benefits of agents, improving clarity on YAML configuration parameters, and updating the sample interaction. Additionally, modify the Agent class to pull the model during initialization, ensuring proper setup for agent functionality.
This commit is contained in:
parent
ca1a73fa76
commit
066df6b369
@ -9,36 +9,42 @@ import TypewriterTextarea from '@site/src/components/TypewriterTextarea';
|
||||
|
||||
# Agents
|
||||
|
||||
Build powerful, flexible agents—backed by LLMs and tools—in a few minutes.
|
||||
An **agent** is an intelligent assistant that understands user requests, communicates using LLMs, and performs actions by invoking appropriate tools (exposed as code).
|
||||
|
||||
Ollama4j’s agent system lets you bring together the best of LLM reasoning and external tool-use using a simple, declarative YAML configuration. No framework bloat, no complicated setup—just describe your agent, plug in your logic, and go.
|
||||
With agents, you can:
|
||||
- Orchestrate multi-step reasoning and tool use (e.g., answering questions, looking up data, making reservations, sending emails, and more)
|
||||
- Automatically select and execute the right tools or actions based on user intent
|
||||
- Maintain conversation context to support dynamic, interactive problem solving
|
||||
- Adapt behavior, persona, or expertise by simply changing configuration—without changing your Java code
|
||||
|
||||
Agents help by acting as an intelligent bridge between users, LLMs, and your application's capabilities. They can automate tasks, provide personalized assistance, and extend what LLMs can do by calling your Java methods or integrating with external systems.
|
||||
|
||||
With Ollama4j, creating an agent is as simple as describing its purpose, available tools, behavior, and preferred language model—all defined in a single YAML file.
|
||||
|
||||
**Why consider building agents using Ollama4j?**
|
||||
|
||||
- **Seamless Customization:** Effortlessly fine-tune your agent's personality, expertise, or workflow by editing the YAML—no need to recompile or modify your Java code.
|
||||
- **Plug-and-Play Extensibility:** Add new tools or swap out existing logic classes without wrestling with framework internals or glue code.
|
||||
- **Rapid Iteration:** Experiment freely. Try different models, instructions, and toolsets to try new behaviors or orchestrations in minutes.
|
||||
- **Clear Separation of Concerns:** Keep your core business logic (Java) and conversational configuration (YAML) distinct, promoting clarity, maintainability, and collaboration.
|
||||
|
||||
---
|
||||
|
||||
**Why use agents in Ollama4j?**
|
||||
|
||||
- **Effortless Customization:** Instantly adjust your agent’s persona, reasoning strategies, or domain by tweaking YAML. No need to touch your compiled Java code.
|
||||
- **Easy Extensibility:** Want new capabilities? Just add or change tools and logic classes—no framework glue or plumbing required.
|
||||
- **Fast Experimentation:** Mix-and-match models, instructions, and tools—prototype sophisticated behaviors or orchestrators in minutes.
|
||||
- **Clean Separation:** Keep business logic (Java) and agent personality/configuration (YAML) separate for maintainability and clarity.
|
||||
|
||||
---
|
||||
|
||||
## Define an Agent in YAML
|
||||
### Define an Agent in YAML
|
||||
|
||||
Specify everything about your agent—what LLM it uses, its “personality,” and all callable tools—in a single YAML file.
|
||||
|
||||
**Agent YAML keys:**
|
||||
**Agent configuration parameters:**
|
||||
|
||||
| Field | Description |
|
||||
|-------------------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||
| `name` | Name of your agent. |
|
||||
| `host` | The base URL for your Ollama server (e.g., `http://localhost:11434`). |
|
||||
| `model` | The LLM backing your agent (e.g., `llama2`, `mistral`, `mixtral`, etc). |
|
||||
| `customPrompt` | _(optional)_ System prompt—instructions or persona for your agent. |
|
||||
| `tools` | List of tools the agent can use. Each tool entry describes the name, function, and parameters. |
|
||||
| `toolFunctionFQCN` | Fully qualified Java class name implementing the tool logic. Must be present on classpath. |
|
||||
| `requestTimeoutSeconds` | _(optional)_ How long (seconds) to wait for agent replies. |
|
||||
| Field | Description |
|
||||
|-------------------------|------------------------------------------------------------------------------------------------|
|
||||
| `name` | Name of your agent. |
|
||||
| `host` | The base URL for your Ollama server (e.g., `http://localhost:11434`). |
|
||||
| `model` | The LLM backing your agent (e.g., `llama3`, `gemma`, `mistral`, etc). |
|
||||
| `customPrompt` | _(optional)_ System prompt—instructions or persona for your agent. |
|
||||
| `tools` | List of tools the agent can use. Each tool entry describes the name, function, and parameters. |
|
||||
| `toolFunctionFQCN` | Fully qualified Java class name implementing the tool logic. Must be present on classpath. |
|
||||
| `requestTimeoutSeconds` | _(optional)_ How long (seconds) to wait for agent replies. |
|
||||
|
||||
YAML makes it effortless to configure and tweak your agent’s powers and behavior—no code changes needed!
|
||||
|
||||
@ -48,7 +54,7 @@ YAML makes it effortless to configure and tweak your agent’s powers and behavi
|
||||
|
||||
---
|
||||
|
||||
## Implement Tool Functions
|
||||
### Implement Tool Functions
|
||||
|
||||
Your agent calls out to Java classes (Tool Functions). Put these implementations on your classpath, register them in YAML.
|
||||
|
||||
@ -58,7 +64,7 @@ Your agent calls out to Java classes (Tool Functions). Put these implementations
|
||||
|
||||
---
|
||||
|
||||
## Instantiating and Running Agents
|
||||
### Instantiating and Running Agents
|
||||
|
||||
Once your agent is described in YAML, bringing it to life in Java takes only a couple of lines:
|
||||
|
||||
@ -69,7 +75,7 @@ The API takes care of wiring up LLMs, tool invocation, and instruction handling.
|
||||
Here's a sample interaction:
|
||||
|
||||
<TypewriterTextarea
|
||||
textContent='[You]: Book a hotel in Mysuru for two guests, from July 20th to July 22nd.
|
||||
textContent='[You]: Book a hotel in Mysuru for two guests, from July 20 to July 22.
|
||||
Alright, I have booked the hotel! Room number 10 booked for 2 guests in Mysuru from July 20th to July 22nd. Here is your booking ID: HB-123'
|
||||
typingSpeed={30}
|
||||
pauseBetweenSentences={1200}
|
||||
|
||||
@ -137,6 +137,7 @@ public class Agent {
|
||||
}
|
||||
Ollama ollama = new Ollama(agentSpec.getHost());
|
||||
ollama.setRequestTimeoutSeconds(120);
|
||||
ollama.pullModel(agentSpec.getModel());
|
||||
return new Agent(
|
||||
agentSpec.getName(),
|
||||
ollama,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user