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>
33 lines
927 B
Kotlin
33 lines
927 B
Kotlin
package com.google.adk.kt.examples.tools
|
|
|
|
import com.google.adk.kt.annotations.Param
|
|
import com.google.adk.kt.annotations.Tool
|
|
import com.google.adk.kt.tools.ToolContext
|
|
|
|
// --8<-- [start:pass_data]
|
|
class DataPassingService {
|
|
/**
|
|
* Stores a value in the temporary session state.
|
|
*/
|
|
@Tool
|
|
fun storeValue(
|
|
context: ToolContext,
|
|
@Param("The value to store.") value: String,
|
|
): String {
|
|
// Store data in the 'temp:' state.
|
|
context.invocationContext.session.state["temp:my_key"] = value
|
|
return "Value stored."
|
|
}
|
|
|
|
/**
|
|
* Retrieves a value from the temporary session state.
|
|
*/
|
|
@Tool
|
|
fun retrieveValue(context: ToolContext): String {
|
|
// Retrieve data from the 'temp:' state.
|
|
val value = context.invocationContext.session.state["temp:my_key"] as? String
|
|
return "Retrieved value: $value"
|
|
}
|
|
}
|
|
// --8<-- [end:pass_data]
|