Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/agents/llm-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ Control whether the agent receives the prior conversation history.
.build();
```

=== "Kotlin"

```kotlin
--8<-- "examples/kotlin/snippets/agents/llm-agent/CapitalAgent.kt:include_contents"
```

!!! note "Go v2.0.0: agent execution modes"

ADK Go v2.0.0 introduces an explicit `Mode` field on `llmagent.Config` that
Expand Down
27 changes: 26 additions & 1 deletion docs/safety/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Safety and Security for AI Agents

<div class="language-support-tag">
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python</span><span class="lst-typescript">TypeScript</span><span class="lst-go">Go</span><span class="lst-java">Java</span>
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python</span><span class="lst-typescript">TypeScript</span><span class="lst-go">Go</span><span class="lst-java">Java</span><span class="lst-kotlin">Kotlin</span>
</div>

As AI agents grow in capability, ensuring they operate safely, securely, and align with your brand values is paramount. Uncontrolled agents can pose risks, including executing misaligned or harmful actions, such as data exfiltration, and generating inappropriate content that can impact your brand’s reputation. **Sources of risk include vague instructions, model hallucination, jailbreaks and prompt injections from adversarial users, and indirect prompt injections via tool use.**
Expand Down Expand Up @@ -368,6 +368,31 @@ Gemini models come with in-built safety mechanisms that can be leveraged to impr
})
```

=== "Kotlin"

```kotlin
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.types.GenerateContentConfig
import com.google.adk.kt.types.HarmBlockThreshold
import com.google.adk.kt.types.HarmCategory
import com.google.adk.kt.types.SafetySetting

val agent =
LlmAgent(
// ...
generateContentConfig =
GenerateContentConfig(
safetySettings =
listOf(
SafetySetting(
category = HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold = HarmBlockThreshold.OFF,
),
),
),
)
```

* **System instructions for safety**: [System instructions](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/safety-system-instructions) for Gemini models on Agent Platform provide direct guidance to the model on how to behave and what type of content to generate. By providing specific instructions, you can proactively steer the model away from generating undesirable content to meet your organization’s unique needs. You can craft system instructions to define content safety guidelines, such as prohibited and sensitive topics, and disclaimer language, as well as brand safety guidelines to ensure the model's outputs align with your brand's voice, tone, values, and target audience.

While these measures are robust against content safety, you need additional checks to reduce agent misalignment, unsafe actions, and brand safety risks.
Expand Down
22 changes: 22 additions & 0 deletions examples/kotlin/snippets/agents/llm-agent/CapitalAgent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package com.google.adk.kt.examples.agents.llmagent

import com.google.adk.kt.agents.Instruction
import com.google.adk.kt.agents.LlmAgent
import com.google.adk.kt.agents.LlmAgent.IncludeContents
import com.google.adk.kt.annotations.Param
import com.google.adk.kt.annotations.Tool
import com.google.adk.kt.models.Gemini
import com.google.adk.kt.runners.InMemoryRunner
import com.google.adk.kt.sessions.InMemorySessionService
import com.google.adk.kt.types.Content
import com.google.adk.kt.types.GenerateContentConfig
import com.google.adk.kt.types.HarmBlockThreshold
import com.google.adk.kt.types.HarmCategory
import com.google.adk.kt.types.Part
import com.google.adk.kt.types.SafetySetting
import com.google.adk.kt.types.Schema
import com.google.adk.kt.types.Type
import kotlinx.coroutines.flow.collect
Expand Down Expand Up @@ -77,8 +81,16 @@ fun main() =
model = Gemini(name = "gemini-flash-latest"),
generateContentConfig =
GenerateContentConfig(
// More deterministic output
temperature = 0.2f,
maxOutputTokens = 250,
safetySettings =
listOf(
SafetySetting(
category = HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold = HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
),
),
),
)
// --8<-- [end:gen_config]
Expand Down Expand Up @@ -123,6 +135,16 @@ fun main() =
)
// --8<-- [end:schema_example]

// --8<-- [start:include_contents]
val statelessAgent =
LlmAgent(
name = "capital_agent",
model = Gemini(name = "gemini-flash-latest"),
// ... other params
includeContents = IncludeContents.NONE,
)
// --8<-- [end:include_contents]

// --8<-- [start:full_example]
val finalAgent =
LlmAgent(
Expand Down
Loading