mirror of
https://github.com/google/adk-docs.git
synced 2026-09-14 16:16:59 +08:00
27e1303857
* Migrating from Map to typed data classes in FuncTool and LongRunningTool kotlin examples * lint cleanup of kotlin snippets * adding gradle wrapper for kotlin snippets * cleaning up build file for kotlin * fixing ktlint_code_style, added focus on included Gradle Wrapper --------- Co-authored-by: Kristopher Overholt <koverholt@google.com>
42 lines
1.2 KiB
Kotlin
42 lines
1.2 KiB
Kotlin
package com.google.adk.kt.examples.tools
|
|
|
|
import com.google.adk.kt.agents.Instruction
|
|
import com.google.adk.kt.agents.LlmAgent
|
|
import com.google.adk.kt.annotations.Param
|
|
import com.google.adk.kt.annotations.Tool
|
|
import com.google.adk.kt.models.Gemini
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
// --8<-- [start:full_example]
|
|
data class StockPrice(val symbol: String, val price: Double)
|
|
|
|
class StockService {
|
|
/**
|
|
* Retrieves the stock price for a given symbol.
|
|
*/
|
|
@Tool
|
|
fun getStockPrice(
|
|
@Param("The stock symbol, e.g. GOOG") symbol: String,
|
|
): StockPrice {
|
|
// In a real app, you would call a stock price API here.
|
|
return StockPrice(symbol = symbol, price = 123.45)
|
|
}
|
|
}
|
|
|
|
fun main() =
|
|
runBlocking {
|
|
val stockService = StockService()
|
|
|
|
val agent =
|
|
LlmAgent(
|
|
name = "stock_agent",
|
|
model = Gemini(name = "gemini-flash-latest"),
|
|
instruction = Instruction("You are a helpful stock assistant."),
|
|
// .generatedTools() is used to get the tools from the annotated class.
|
|
tools = stockService.generatedTools(),
|
|
)
|
|
|
|
// ... use the agent ...
|
|
}
|
|
// --8<-- [end:full_example]
|