Skip to content

Commit 70f5075

Browse files
committed
Update Agents/Tools pages
1 parent 7878afa commit 70f5075

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

documentation/modules/ROOT/pages/19_agents_tools.adoc

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
The real deal to bring AI for your development process is when you can create a real interaction between services you build and/or use with the LLM.
66

7-
This section will use AI to trigger an email service from our local application.
7+
This section will use AI to trigger an email service from our local application. To do this, we'll use LangChain4j's concept of Agents and Tools.
88

9+
Agents operate by utilizing a language model to decipher a series of actions, unlike chains where actions are pre-programmed. Ie. agents leverage a language model as a cognitive engine to decide on the actions (tools) and their order.
910

10-
IMPORTANT: We keep assuming that you'll be working inside the project folder that was created before. In this case, `{project-ai-name}`.
11+
You can read more about this concept in the https://docs.quarkiverse.io/quarkus-langchain4j/dev/agent-and-tools.html[Quarkus LangChain4j Documentation]
1112

1213
== Add the Mailer and Mailpit extensions
1314

14-
Just open a new terminal window, and make sure you’re at the root of your `{project-ai-name}` project, then run:
15+
Open a new terminal window, and make sure you’re at the root of your `{project-ai-name}` project, then run:
1516

1617
[tabs]
1718
====
@@ -64,7 +65,9 @@ public class EmailService {
6465
@Tool("send the given content by email")
6566
public void sendAnEmail(String content) {
6667
Log.info("Sending an email: " + content);
67-
mailer.send(Mail.withText("sendMeALetter@quarkus.io", "A poem for you", content).setFrom("origin@quarkus.io"));
68+
mailer.send(Mail
69+
.withText("sendMeALetter@quarkus.io", "A poem for you", content)
70+
.setFrom("origin@quarkus.io"));
6871
}
6972
7073
}
@@ -73,7 +76,11 @@ public class EmailService {
7376

7477
== Create the AI service with prompt context
7578

76-
Let's create an interface for our AI service, but with `SystemMessage` and `UserMessage` this time.
79+
Let's create an interface for our AI service, but with `SystemMessage` and `UserMessage` this time.
80+
`SystemMessage` gives context to the AI Model.
81+
In this case we tell it that it should craft a message as if it is written by a professional poet.
82+
The `UserMessage` is the actual instruction/question we're sending to the AI model. As you can see in the example below,
83+
you can format and parametrize the UserMessage, translating structured content to text and vice-versa.
7784

7885
Create a new `AssistantWithContext` Java interface in `src/main/java` in the `com.redhat.developers` package with the following contents:
7986

@@ -107,7 +114,7 @@ Note that this assistant references the email service as a tool.
107114

108115
== Create a email sending resource
109116

110-
Now we create a resource that builds the whole interaction.
117+
Now we create a resource that builds the interaction and calls the service with the required parameters (topic & lines).
111118

112119
Create a new `EmailMeAPoemResource` Java class in `src/main/java` in the `com.redhat.developers` package with the following contents:
113120

@@ -138,24 +145,27 @@ public class EmailMeAPoemResource {
138145

139146
== Adding email service properties to your configuration
140147

141-
Add the following properties to your `application.properties` so that it looks like:
148+
Update the following properties in your `application.properties`
149+
150+
IMPORTANT: The LangChain4j `demo` key currently does not support tools, so you will need to use a real OpenAI key for the email service to be called by the OpenAI model.
151+
You can create an account over at https://platform.openai.com/[OpenAI] if you'd like to see this in action.
152+
153+
NOTE: If you do not want to create an OpenAI key, you can still test the below scenario, it just won't send an email.
142154

143155
[#quarkuspdb-update-props]
144156
[.console-input]
145157
[source,config,subs="+macros,+attributes"]
146158
----
147-
quarkus.langchain4j.openai.api-key=demo
159+
quarkus.langchain4j.openai.api-key=<YOUR OPENAI KEY>
148160
149161
quarkus.langchain4j.openai.log-requests=true
150162
quarkus.langchain4j.openai.log-responses=true
151163
quarkus.langchain4j.openai.timeout=60s
152164
153-
%dev.quarkus.mailer.host=localhost
154-
%dev.quarkus.mailer.port=1025
155165
%dev.quarkus.mailer.mock=false
156166
----
157167

158-
By setting those properties Quarkus will use DevServices to instantiate a local email service for you (development time only).
168+
Because we haven't configured the local email service, Quarkus will use DevServices to instantiate and configure a local email service for you (in Dev Mode only!).
159169

160170
You can check it running:
161171

@@ -197,12 +207,12 @@ An example of output (it can vary on each prompt execution):
197207
I have composed a poem about Quarkus. I have sent it to you via email. Let me know if you need anything else
198208
----
199209

200-
More than see this on your terminal, you can check the "real" email.
210+
If you have a valid OpenAI key configured, you can check the "real" email:
201211

202-
First, open the DevUI and click on the Mailpit arrow.
212+
First, open the http://localhost:8080/q/dev-ui[DevUI, window=_blank] and click on the Mailpit arrow.
203213

204214
image::devui-mailpit.png[]
205215

206-
Now you can see the email it was sent:
216+
Now you can see the email that was sent:
207217

208218
image::mailpit-email-sent.png[]

0 commit comments

Comments
 (0)