6  Tool use

rtemis.llm supports creating agents with access to tools. Tools are functions that the agent can choose to call during the generation process.

For security reasons, the package provides a list of pre-built tools, which are hashed and validated at runtime, to reduce the risk of malicious code execution. The allow_custom_tools argument in create_agent() can be set to TRUE to allow the use of custom tools. The create_tool() function can be used to create custom tools.

6.1 Built-in tools

library(rtemis.llm)
  .:rtemis.llm v.0.8.8 · aarch64-apple-darwin23

Print list of built-in tools:

available_tools()

  Built-in tools:

* tool_arxiv (function_name: query_arxiv)
  Search arXiv.org for academic papers in physics, mathematics, computer science, quantitative biology, quantitative finance, statistics, electrical engineering, systems science, and economics.
* tool_datetime (function_name: get_current_datetime)
  Get the current date and time in ISO format.
* tool_duckduckgo_ia (function_name: query_duckduckgo_ia)
  Search DuckDuckGo Instant Answer API.  Use single-word queries for best results. Some queries may not return any results.
* tool_semanticscholar (function_name: query_semanticscholar)
  Search Semantic Scholar for academic papers across science, technology, medicine, social sciences, and humanities.
* tool_wikipedia (function_name: query_wikipedia)
  Search Wikipedia for articles and return either the introduction or the full article text. Useful for retrieving factual information from Wikipedia. One strategy is to get multiple articles' introduction first and then refine the search to get the full text of the most relevant article.

Create two agents, one without and with access to the datetime tool:

agent_zero <- create_agent(
  config_Ollama(
    model_name = "gemma4:e4b",
    temperature = 0.2
  ),
  system_prompt = "You are a helpful assistant.",
  name = "AgentZero"
)
agent_current <- create_agent(
  config_Ollama(
    model_name = "gemma4:e4b",
    temperature = 0.2
  ),
  system_prompt = "You are a helpful assistant.",
  name = "AgentCurrent",
  tools = list(tool_datetime)
)

Generate a response from both agents to the same prompt:

res_zero <- generate(agent_zero, "What is the current date and time?")
2026-10-04 02:08:11 [gemma4:e4b] working... [generate]
2026-10-04 02:08:31 [gemma4:e4b] done. [generate]
res_zero
$system
[AgentZero System] You are a helpful assistant. 

$user
[Input] What is the current date and time? 

$assistant
[AgentZero Reasoning] Thinking Process:

1.  **Identify the core request:** The user is asking for the "current date and time."
2.  **Analyze capability constraints:** As an AI language model, I do not have real-time access to the physical clock or the user's local time zone. My responses are generated based on the time the model was trained or the time the server processes the request, but this is not reliable or accurate for the user's immediate needs.
3.  **Determine the necessary response:** I must inform the user that I cannot provide the *actual* current time because I lack real-time clock access.
4.  **Provide a helpful alternative:** To be helpful, I must instruct the user on how *they* can find the accurate time (e.g., checking a reliable clock, device, or search engine).
5.  **Formulate the answer:** Be polite, state the limitation clearly, and offer the solution. (Self-correction: Do not guess the time; state the limitation directly.)

[AgentZero Response] I do not have access to a real-time clock, so I cannot tell you the exact current date and time.

To get the accurate time, please check a reliable clock, your computer's system clock, or use a search engine. 

attr(,"agent_output")
[1] TRUE
res_current <- generate(agent_current, "What is the current date and time?")
2026-10-04 02:08:31 [gemma4:e4b] working... [generate]
2026-10-04 02:08:34 [gemma4:e4b] done. [generate]
2026-10-04 02:08:34 Agent wants to perform 1 tool call. [generate]
2026-10-04 02:08:34 Invoking tool: get_current_datetime [generate]
2026-10-04 02:08:34 Tool get_current_datetime returned response. [generate]
2026-10-04 02:08:34 Sending tool responses back to agent... [generate]
2026-10-04 02:08:44 [gemma4:e4b] done. [generate]
res_current
$system
[AgentCurrent System] You are a helpful assistant. 

$user
[Input] What is the current date and time? 

$assistant
[AgentCurrent Reasoning] The user is asking for the current date and time. I have a tool called `get_current_datetime` that can provide this information. I should call this tool.

[AgentCurrent Tool Call]
[
  {
    "id": "call_487zenfu",
    "function": {
      "index": 0,
      "name": "get_current_datetime",
      "arguments": {}
    }
  }
] 

$tool
[get_current_datetime Tool Response]
{"date":"2026-10-04","time":"02:08:34","timezone":"America/Los_Angeles"} 

$user
[Agent Message]
Tool 'get_current_datetime' response:

{"date":"2026-10-04","time":"02:08:34","timezone":"America/Los_Angeles"}

Acknowledge the tools used and include citations where applicable. If you do not have sufficient information, you may use up to 2 more tool call rounds, if necessary. Remember the original query you are answering:

"What is the current date and time?"
 

$assistant
[AgentCurrent Reasoning] The user is asking for the current date and time.
I have already called the `get_current_datetime` tool and received the response: `{"date":"2026-10-04","time":"02:08:34","timezone":"America/Los_Angeles"}`.
I need to present this information clearly to the user, acknowledging the tool use and providing the citation.

Plan:
1. Extract the date, time, and timezone from the tool response.
2. Formulate a natural language answer.
3. Include the citation for the tool used.

[AgentCurrent Response] The current date and time is October 4, 2026, at 02:08:34 in the America/Los_Angeles timezone (Tool: get_current_datetime). 

attr(,"agent_output")
[1] TRUE
© 2026 E.D. Gennatas