Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security AI Assistant] Adds ability to specify LangSmith config and APM URL for tracing in cloud environments #180227

Merged
merged 7 commits into from
Apr 8, 2024

Conversation

spong
Copy link
Member

@spong spong commented Apr 5, 2024

Summary

While we wait for #178304, this is a PR for allowing users to specify their LangSmith config for tracing in cloud environments by only storing them in session storage. This is also behind an experimental feature flag and must be enabled with the assistantModelEvaluation flag ala:

xpack.securitySolution.enableExperimental: [ 'assistantModelEvaluation']

Note I: xpack.securitySolution.enableExperimental should be allowlisted in cloud, but I have manually enabled via source for initial testing.
Note II: I have verified the above is configurable on cloud deployments 👍

The new traceOptions are stored with the elasticAssistantDefault.traceOptions key, and the following keys:

{
  apmUrl : "${basepath}/app/apm"
  langSmithApiKey: "🫣"
  langSmithProject: "Cloud Testing"
}

The langSmithApiKey and langSmithProject are then sent along with the request to /actions/connector/{connectorId}/_execute, and a new LangChainTracer is created using the values. The tracing infrastructue was already in place for evaluation, so no other changes were necessary.

The apmUrl value is now used for the View APM trace for message action, so if you have set up a remote APM server, you can now link directly to that instance from the message.

A basic UI was added for these fields under the Run step of the Evaluation Settings. No need to save or run an evaluation once entering. Fields are immediately stored in session storage upon entry.

Test Instructions

Click on the latest Kibana Buildkite build, go to the ci:cloud-deploy cluster (grabbing creds from vault), then set a LangChain Project/API key in the above UI, then make a request to the LLM and verify the trace is collected in the LangSmith UI:

Note

Only LangChain codepaths can be traced to LangSmith, so you must ensure LangChain is enabled by either turning on the Knowledge Base or enabling the Alert tools. The former can't be done in default ci:cloud-deploy deployments as they only have a 1GB ML nodes, so it is easiest to just turn on the Alert tools.

Checklist

Delete any items that are not applicable to this PR.

@spong spong added enhancement New value added to drive a business result release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. ci:cloud-deploy Create or update a Cloud deployment Feature:Security Assistant Security Assistant Team:Security Generative AI Security Generative AI labels Apr 5, 2024
@spong spong self-assigned this Apr 5, 2024
@spong spong marked this pull request as ready for review April 8, 2024 18:09
@spong spong requested review from a team as code owners April 8, 2024 18:09
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

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

Thank you 🙇

@spong spong enabled auto-merge (squash) April 8, 2024 21:06
@kibana-ci
Copy link
Collaborator

kibana-ci commented Apr 8, 2024

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 17.0MB 17.0MB +2.6KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @spong

@spong spong merged commit 16c0ab8 into elastic:main Apr 8, 2024
37 checks passed
@kibanamachine kibanamachine added v8.14.0 backport:skip This commit does not require backporting labels Apr 8, 2024
spong added a commit that referenced this pull request Apr 10, 2024
…tion via env vars (#180426)

## Summary

With #180227, LangSmith
configuration (Project & API Key) could no longer be specified using
environment variables when working locally. This fixes that issue, which
was caused by sending `''` for `langSmithProject` and `langSmithApiKey`
instead of `undefined`.

To test, set the below env vars, then start kibana. Be sure to not have
the UI trace options set as shown in
#180227.


```
# LangChain LangSmith
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
export LANGCHAIN_API_KEY="🫣"
export LANGCHAIN_PROJECT="Best Project Ever"
```
andrew-goldstein added a commit to andrew-goldstein/kibana that referenced this pull request Apr 18, 2024
…d deployments

### Summary

This PR enables LangSmith tracing for the [AI Insights](elastic#180611) feature in cloud deployments.

LangSmith project names and API keys are specified using the same UI and patterns introduced by @spong in <elastic#180227>

### Details

To enable LangSmith tracing in cloud deployments, configure the following `xpack.securitySolution.enableExperimental` feature flags:

```
xpack.securitySolution.enableExperimental: ['assistantModelEvaluation', 'assistantAlertsInsights']
```

- The `assistantModelEvaluation` feature flag enables the `Evaluation` settings category in the assistant. The LangSmith project name and API key are configured here
- The `assistantAlertsInsights` feature flag enables the AI Insights feature, which is off by default at the time of this writing

After enabling the feature flags above:

1) Click the `AI Assistant` button anywhere in the Security Solution to launch the assistant

2) Click the settings gear in the assistant

3) Click the `Evaluation` settings category

4) Click `Show Trace Options (for internal use only)`

5) Specify a `LangSmith Project` and `LangSmith API Key` per the screenshot below:

![langsmith_settings](https://github.com/elastic/kibana/assets/4459398/896c8155-3a06-4381-becf-b846b5aba426)
andrew-goldstein added a commit that referenced this pull request Apr 18, 2024
…eployments (#181159)

## [Security Solution] [AI Insights] Enable LangSmith tracing in cloud deployments

### Summary

This PR enables LangSmith tracing for the [AI Insights](#180611) feature in cloud deployments.

LangSmith project names and API keys are specified using the same UI and patterns introduced by @spong in <#180227>

### Details

To enable LangSmith tracing in cloud deployments, configure the following `xpack.securitySolution.enableExperimental` feature flags:

```
xpack.securitySolution.enableExperimental: ['assistantModelEvaluation', 'assistantAlertsInsights']
```

- The `assistantModelEvaluation` feature flag enables the `Evaluation` settings category in the assistant. The LangSmith project name and API key are configured here
- The `assistantAlertsInsights` feature flag enables the AI Insights feature, which is off by default at the time of this writing

After enabling the feature flags above:

1) Click the `AI Assistant` button anywhere in the Security Solution to launch the assistant

2) Click the settings gear in the assistant

3) Click the `Evaluation` settings category

4) Click `Show Trace Options (for internal use only)`

5) Specify a `LangSmith Project` and `LangSmith API Key` per the screenshot below:

![langsmith_settings](https://github.com/elastic/kibana/assets/4459398/896c8155-3a06-4381-becf-b846b5aba426)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 18, 2024
…eployments (elastic#181159)

## [Security Solution] [AI Insights] Enable LangSmith tracing in cloud deployments

### Summary

This PR enables LangSmith tracing for the [AI Insights](elastic#180611) feature in cloud deployments.

LangSmith project names and API keys are specified using the same UI and patterns introduced by @spong in <elastic#180227>

### Details

To enable LangSmith tracing in cloud deployments, configure the following `xpack.securitySolution.enableExperimental` feature flags:

```
xpack.securitySolution.enableExperimental: ['assistantModelEvaluation', 'assistantAlertsInsights']
```

- The `assistantModelEvaluation` feature flag enables the `Evaluation` settings category in the assistant. The LangSmith project name and API key are configured here
- The `assistantAlertsInsights` feature flag enables the AI Insights feature, which is off by default at the time of this writing

After enabling the feature flags above:

1) Click the `AI Assistant` button anywhere in the Security Solution to launch the assistant

2) Click the settings gear in the assistant

3) Click the `Evaluation` settings category

4) Click `Show Trace Options (for internal use only)`

5) Specify a `LangSmith Project` and `LangSmith API Key` per the screenshot below:

![langsmith_settings](https://github.com/elastic/kibana/assets/4459398/896c8155-3a06-4381-becf-b846b5aba426)

(cherry picked from commit 89609fe)
kibanamachine referenced this pull request Apr 18, 2024
…cloud deployments (#181159) (#181203)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[Security Solution] [AI Insights] Enable LangSmith tracing in cloud
deployments (#181159)](#181159)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Andrew
Macri","email":"andrew.macri@elastic.co"},"sourceCommit":{"committedDate":"2024-04-18T19:01:27Z","message":"[Security
Solution] [AI Insights] Enable LangSmith tracing in cloud deployments
(#181159)\n\n## [Security Solution] [AI Insights] Enable LangSmith
tracing in cloud deployments\r\n\r\n### Summary\r\n\r\nThis PR enables
LangSmith tracing for the [AI
Insights](#180611) feature in
cloud deployments.\r\n\r\nLangSmith project names and API keys are
specified using the same UI and patterns introduced by @spong in
<https://github.com/elastic/kibana/pull/180227>\r\n\r\n###
Details\r\n\r\nTo enable LangSmith tracing in cloud deployments,
configure the following `xpack.securitySolution.enableExperimental`
feature flags:\r\n\r\n```\r\nxpack.securitySolution.enableExperimental:
['assistantModelEvaluation', 'assistantAlertsInsights']\r\n```\r\n\r\n-
The `assistantModelEvaluation` feature flag enables the `Evaluation`
settings category in the assistant. The LangSmith project name and API
key are configured here\r\n- The `assistantAlertsInsights` feature flag
enables the AI Insights feature, which is off by default at the time of
this writing\r\n\r\nAfter enabling the feature flags above:\r\n\r\n1)
Click the `AI Assistant` button anywhere in the Security Solution to
launch the assistant\r\n\r\n2) Click the settings gear in the
assistant\r\n\r\n3) Click the `Evaluation` settings category\r\n\r\n4)
Click `Show Trace Options (for internal use only)`\r\n\r\n5) Specify a
`LangSmith Project` and `LangSmith API Key` per the screenshot
below:\r\n\r\n![langsmith_settings](https://github.com/elastic/kibana/assets/4459398/896c8155-3a06-4381-becf-b846b5aba426)","sha":"89609fe596d79b7d2eb4f209c5388824f9b279c1","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:
SecuritySolution","Team:Security Generative
AI","v8.14.0","v8.15.0","Feature:AI Insights"],"title":"[Security
Solution] [AI Insights] Enable LangSmith tracing in cloud
deployments","number":181159,"url":"https://github.com/elastic/kibana/pull/181159","mergeCommit":{"message":"[Security
Solution] [AI Insights] Enable LangSmith tracing in cloud deployments
(#181159)\n\n## [Security Solution] [AI Insights] Enable LangSmith
tracing in cloud deployments\r\n\r\n### Summary\r\n\r\nThis PR enables
LangSmith tracing for the [AI
Insights](#180611) feature in
cloud deployments.\r\n\r\nLangSmith project names and API keys are
specified using the same UI and patterns introduced by @spong in
<https://github.com/elastic/kibana/pull/180227>\r\n\r\n###
Details\r\n\r\nTo enable LangSmith tracing in cloud deployments,
configure the following `xpack.securitySolution.enableExperimental`
feature flags:\r\n\r\n```\r\nxpack.securitySolution.enableExperimental:
['assistantModelEvaluation', 'assistantAlertsInsights']\r\n```\r\n\r\n-
The `assistantModelEvaluation` feature flag enables the `Evaluation`
settings category in the assistant. The LangSmith project name and API
key are configured here\r\n- The `assistantAlertsInsights` feature flag
enables the AI Insights feature, which is off by default at the time of
this writing\r\n\r\nAfter enabling the feature flags above:\r\n\r\n1)
Click the `AI Assistant` button anywhere in the Security Solution to
launch the assistant\r\n\r\n2) Click the settings gear in the
assistant\r\n\r\n3) Click the `Evaluation` settings category\r\n\r\n4)
Click `Show Trace Options (for internal use only)`\r\n\r\n5) Specify a
`LangSmith Project` and `LangSmith API Key` per the screenshot
below:\r\n\r\n![langsmith_settings](https://github.com/elastic/kibana/assets/4459398/896c8155-3a06-4381-becf-b846b5aba426)","sha":"89609fe596d79b7d2eb4f209c5388824f9b279c1"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/181159","number":181159,"mergeCommit":{"message":"[Security
Solution] [AI Insights] Enable LangSmith tracing in cloud deployments
(#181159)\n\n## [Security Solution] [AI Insights] Enable LangSmith
tracing in cloud deployments\r\n\r\n### Summary\r\n\r\nThis PR enables
LangSmith tracing for the [AI
Insights](#180611) feature in
cloud deployments.\r\n\r\nLangSmith project names and API keys are
specified using the same UI and patterns introduced by @spong in
<https://github.com/elastic/kibana/pull/180227>\r\n\r\n###
Details\r\n\r\nTo enable LangSmith tracing in cloud deployments,
configure the following `xpack.securitySolution.enableExperimental`
feature flags:\r\n\r\n```\r\nxpack.securitySolution.enableExperimental:
['assistantModelEvaluation', 'assistantAlertsInsights']\r\n```\r\n\r\n-
The `assistantModelEvaluation` feature flag enables the `Evaluation`
settings category in the assistant. The LangSmith project name and API
key are configured here\r\n- The `assistantAlertsInsights` feature flag
enables the AI Insights feature, which is off by default at the time of
this writing\r\n\r\nAfter enabling the feature flags above:\r\n\r\n1)
Click the `AI Assistant` button anywhere in the Security Solution to
launch the assistant\r\n\r\n2) Click the settings gear in the
assistant\r\n\r\n3) Click the `Evaluation` settings category\r\n\r\n4)
Click `Show Trace Options (for internal use only)`\r\n\r\n5) Specify a
`LangSmith Project` and `LangSmith API Key` per the screenshot
below:\r\n\r\n![langsmith_settings](https://github.com/elastic/kibana/assets/4459398/896c8155-3a06-4381-becf-b846b5aba426)","sha":"89609fe596d79b7d2eb4f209c5388824f9b279c1"}}]}]
BACKPORT-->

Co-authored-by: Andrew Macri <andrew.macri@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting ci:cloud-deploy Create or update a Cloud deployment enhancement New value added to drive a business result Feature:Security Assistant Security Assistant release_note:skip Skip the PR/issue when compiling release notes Team:Security Generative AI Security Generative AI Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.14.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants