from typing import Dict, Any
from oci.addons.adk import Agent, AgentClient, tool
@tool
def get_weather(location: str) -> Dict[str, Any]:
"""Get the weather for a given location.
Args:
location(str): The location for which weather is queried
"""
return {"location": location, "temperature": 72, "unit": "F"}
def main():
client = AgentClient(
auth_type="api_key",
profile="DEFAULT",
region="us-chicago-1"
)
agent = Agent(
client=client,
agent_endpoint_id="ocid1...",
instructions="Perform weather queries using the given tools",
tools=[get_weather]
)
agent.setup()
input = "Is it cold in Seattle?"
response = agent.run(input)
response.pretty_print()
if __name__ == "__main__":
main()
Java 🔗
WeatherAgent.java
package demos.singleTurnSingleTool.WeatherAgent;
import com.oracle.bmc.ConfigFileReader;
import com.oracle.bmc.adk.agent.Agent;
import com.oracle.bmc.adk.agent.RunOptions;
import com.oracle.bmc.adk.client.AgentClient;
import com.oracle.bmc.adk.tools.FunctionTool;
import com.oracle.bmc.adk.run.RunResponse;
import com.oracle.bmc.auth.BasicAuthenticationDetailsProvider;
import com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider;
import java.lang.reflect.Method;
import java.util.Arrays;
public class WeatherAgent {
@Tool(name = "getWeather", description = "Get weather of a given location")
public static Map<String, String> getWeather(
@Param(description = "The location") String location) {
Map<String, String> weather = new HashMap<>();
weather.put("location", location);
weather.put("temperature", "72");
weather.put("unit", "F");
return weather;
}
public static void main(String[] args) throws Exception {
final String configLocation = "~/.oci/config";
final String configProfile = "DEFAULT";
BasicAuthenticationDetailsProvider authProvider =
new SessionTokenAuthenticationDetailsProvider(
ConfigFileReader.parse(configLocation, configProfile));
AgentClient agentClient = AgentClient.builder()
.authProvider(authProvider)
.region("us-chicago-1")
.build();
FunctionTool getWeatherTool =
FunctionTool.fromMethod(WeatherAgent.class, "getWeather", String.class);
Agent agent = Agent.builder()
.client(agentClient)
.agentEndpointId("YOUR_AGENT_ENDPOINT_ID")
.instructions("Perform weather queries using the given tools.")
.tools(Arrays.asList(getWeatherTool))
.build();
agent.setup();
final String input = "Is it cold in Seattle";
final Integer maxStep = 3;
RunOptions runOptions = RunOptions.builder().maxSteps(maxStep).build();
RunResponse response = agent.run(input, runOptions);
response.prettyPrint();
}
}