5  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.

5.1 Built-in tools

library(rtemis.llm)
  .:rtemis.llm v.0.8.0 🌊 aarch64-apple-darwin20

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-04-23 18:01:21 [gemma4:e4b] working... [generate]
2026-04-23 18:01: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.  **Analyze the Request:** The user is asking for "the current date and time."
2.  **Identify Constraints/Limitations:** As an AI model, I do not have real-time access to the physical clock of the user or the server running the model in a way that guarantees absolute, universally accurate, second-by-second time. My responses are generated based on my training data and the current operational environment, but this environment time can sometimes be delayed or generalized.
3.  **Determine the Best Practice Response:**
    *   I must state that I cannot provide the *exact* real-time clock reading.
    *   I must provide the date and time *as of the moment of generation* (or use a placeholder/disclaimer).
    *   I must advise the user to check a reliable, local source (like their device's clock or a search engine) for the most accurate information.
4.  **Formulate the Answer:** (Self-Correction/Refinement: Instead of just saying "I don't know," I should provide the date I am operating on, and then add the necessary disclaimer.)

*(Self-Correction during drafting: Since I cannot know the user's timezone, I must explicitly mention that the time provided is based on a general server time and is not necessarily their local time.)*

[AgentZero Response] I do not have access to a real-time clock that reflects your specific location or timezone.

To get the most accurate current date and time, please check the clock on your device (computer, phone, etc.).

However, I can tell you that **as of my last update, the date is [Current Date]**. Please note that this time is based on my operational server time and may not match your local time zone. 
res_current <- generate(agent_current, "What is the current date and time?")
2026-04-23 18:01:31 [gemma4:e4b] working... [generate]
2026-04-23 18:01:32 [gemma4:e4b] done. [generate]
2026-04-23 18:01:32 Agent wants to perform 1 tool call. [generate]
2026-04-23 18:01:32 Invoking tool: get_current_datetime [generate]
2026-04-23 18:01:32 Tool get_current_datetime returned response. [generate]
2026-04-23 18:01:32 Sending tool responses back to agent... [generate]
2026-04-23 18:01:38 [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_1uhoj3nr",
    "function": {
      "index": 0,
      "name": "get_current_datetime",
      "arguments": {}
    }
  }
] 

$tool
[get_current_datetime Tool Response]
{"date":"2026-04-23","time":"18:01:32","timezone":"America/Los_Angeles"} 

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

{"date":"2026-04-23","time":"18:01:32","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 a response.
The response is: `{"date":"2026-04-23","time":"18:01:32","timezone":"America/Los_Angeles"}`.
I need to present this information to the user, acknowledging the tool use and providing citations.

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 **April 23, 2026, at 6:01:32 PM** in the America/Los_Angeles timezone (as of the time the tool was called).

***
*Source: get_current_datetime* 
© 2026 E.D. Gennatas