Skip to content

Conversation

@marinkovicmarko
Copy link
Contributor

Add documentation on how to implement custom features.


Type of the changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tests improvement
  • Refactoring

Checklist

  • The pull request has a description of the proposed change
  • I read the Contributing Guidelines before opening the pull request
  • The pull request uses develop as the base branch
  • Tests for the changes have been added
  • All new and existing tests passed
Additional steps for pull requests adding a new feature
  • An issue describing the proposed change exists
  • The pull request includes a link to the issue
  • The change was discussed and approved in the issue
  • Docs have been added / updated

@github-actions
Copy link

Qodana for JVM

1254 new problems were found

Inspection name Severity Problems
Check Kotlin and Java source code coverage 🔶 Warning 1234
Missing KDoc for public API declaration 🔶 Warning 20
@@ Code coverage @@
+ 72% total lines covered
18063 lines analyzed, 13017 lines covered
# Calculated according to the filters of your coverage tool

☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

Features provide a way to extend and enhance the functionality of AI agents at runtime. They are designed to be modular
and composable, allowing you to mix and match them according to your needs.

In addition to features that are available in Koog out of the box, you can also implement your own features by
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to features-overview and update that page to clearly list the predefined features and mention and link to this new page about custom features from there as well


Koog provides two interfaces that you can extend to implement custom features:

- `AIAgentGraphFeature`: Represents a feature specific to [agents that have defined workflows](complex-workflow-agents.md) (graph-based agents).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To implement a custom feature, you need to create a feature structure according to the following steps:

1. Create a feature class.
2. Define a configuration class.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that it's an extension of the FeatureConfig class with a link to the API?

- `interceptSubgraphExecutionCompleted`: After a subgraph completes.
- `interceptSubgraphExecutionFailed`: When a subgraph execution fails.

Note that interceptors are feature-scoped: only the feature that registers a handler receives those events (subject to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a note?) Also, I am lost at this point. You never mentioned handlers before this point. Event handlers are a predefined feature, so I am not sure if that's what you mean. The FeatureConfig subclass in your example doesn't have setEventFilter overridden. If this is an important note, I'd expand on this, provide some context and links.


### Disabling event filtering for a feature

Some features, such as debugger and OpenTelemetry, must observe the entire event stream. If your feature depends on the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link?

### Disabling event filtering for a feature

Some features, such as debugger and OpenTelemetry, must observe the entire event stream. If your feature depends on the
full event stream, disable event filtering by overriding `setEventFilter` in your feature configuration to ignore custom
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you mention setEventFilter again, but it is not at all evident what it's for and why you need to make it always return true (disable events filtering) if the feature "depends on the full event stream". Are some events filtered by default?


## Example: A basic logging feature

The following example shows how to implement a basic logging feature that logs agent lifecycle events. The example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "The example" at the end here?)

```kotlin
class LoggingFeature(private val logger: KLogger) {
class Config : FeatureConfig() {
var loggerName: String = "agent-logs"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this loggerName if it's not used anywhere?

override fun createInitialConfig(): Config = Config()

override fun install(config: Config, pipeline: AIAgentGraphPipeline) : LoggingFeature {
val logging = LoggingFeature(logger = logger)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this logger come from that you pass as the logger argument in the constructor?

}
}
```
<!--- KNIT example-custom-features-04.kt -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to show how to install the feature, or is it straightforward? In the first example, you pass a string to the property when installing the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants