Commit graph

31 commits

Author SHA1 Message Date
Forrest 2d8e6d3776
always generate request IDs server-side (#31760)
* server-side request ids

* update e-ref
2023-09-13 16:08:11 +00:00
Hugo Shaka dac5af41d0
Add the ability to run a specific tool to Assist. (#31113)
This commit contains:
- a refactoring of the model action logic to be exposed through the
  `DoAction` function
- Expose `RunTool()` capability through ai.Client and assist.Assist
- Add the "audit-query" action that invokes directly the audit
  generation tool
2023-08-31 20:38:32 +00:00
Joel b255a22e3a
Add access lists to unified resource cache (#31314)
* add access lists to unified resource cache

* check that list got written to URW

* watch access lists

* update unified resource cache tests

* update e pointer

* update e

* update e

* update gomod and e

* don't mess with e and update it seperately. cc @mdwn

* correct godoc

* don't use x/reflect for now
2023-08-31 19:30:58 +00:00
Hugo Shaka bfae370618
stream audit query responses (#31092)
* stream audit query responses

* fixup! stream audit query responses

* fixup! fixup! stream audit query responses
2023-08-30 19:41:45 +00:00
Joel b0eac11430
Remove dead KNNRetriever class (#31176)
* Remove dead KNNRetriever class

* go mod tidy

* add back some needed fns

* fmt

* nolint markings for now
2023-08-30 00:25:13 +00:00
Justinas Stankevičius c1050a265c
Fix flaky embedding processor test (#31106) 2023-08-29 07:59:33 +00:00
Hugo Shaka baa3f0b178
assist: Implement audit query generation tool (#30850)
* Implement audit generation tool

* license

* Update lib/ai/model/tools/auditquery.go

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>

* address feedback

* fixup! address feedback

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
2023-08-25 17:59:24 +00:00
Joel 2fd8f75e38
[Assist] Generalize embeddings system (#30835)
* generalize embeddings

* add test for mapping

* use existing mapper

* add streaming apis

* update embedding processor tests

* delete unused code

* fix tests

* Update lib/ai/embeddingprocessor.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Update lib/ai/embeddingprocessor.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Update lib/ai/embeddingprocessor.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* fix feedback

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-08-23 20:01:56 +00:00
Hugo Shaka 88209b52e3
assist: Split ai/model into smaller packages (#30834)
* assist: Split ai/model into smaller packages

* license
2023-08-23 12:56:51 +00:00
Joel 22ac430617
assist: basic access request integration (#29457)
* implement access request integration

* fix tests

* remove unused code

* various fixes

* remove debug printsa

* address minor feedback

* <address minor feedback

* gci

* address nits

* fix extraneous import

* huh

* fix broken tests

* fix lint

* fix test
2023-08-16 15:57:24 +00:00
Justinas Stankevičius 18016e52e8
Fix node equality check in embedding processor (#30325)
* Fix node equality check in embedding processor

* Apply minor suggestions from code review

* Make process() private, test using only public API

* Remove an unused function

* Update lib/ai/embeddingprocessor.go

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2023-08-16 10:41:53 +00:00
Andrew Burke ad734be859
Re-add ServerInfo reconciler with better backend performance (#30301)
This change re-adds the ServerInfo reconciler that was removed in #30190
due to an unexpected increase in backend usage. This version decreases
the load on the backend by:
- Streaming nodes from the cache instead of the backend
- Increasing the time between batches
- Adding an additional wait between reconciliation loops
2023-08-15 16:15:22 +00:00
Jakub Nyckowski e572328d2d
[Assist] Add in SSH context Assist endpoints (#30319)
* Add in SSH context Assist endpoints

This change introduces web endpoints used by Assist to support in SSH context functionality in the WebUI. Now a user will be able to generate Bash command and explain output in the terminal (like application logs).

* Remove mockup web UI

* Make the linter happy

* Remove unnecessary comments and add missing documentation

This commit removes a redundant comment on the AI model selection in client.go that suggested a model change that is not needed. It also adds missing documentation in chat.go, to clarify the purpose and functionality of the Reply function.

* Revert ws.WriteControl to use real time.

Usage of the fake clock was failing the tests, and it's not really beneficial in this case.
2023-08-14 19:03:18 +00:00
Hugo Shaka 8dbd3c3069
assist: move embeddings in a separate library, add tool config, opportunistic node lookup (#29716)
* assist: extract embedding types into a dedicated module

* assist: allow the embedding tool to query nodes from proxy cache

This commit does two things:
- Introduce a new toolsConfig structure to pass all required clients to
  the tools. This can also be used to enable or disable specicifc tools,
  which helps with testing
- Pass the proxy node cache and the request access checker to the
  embedding tool so it can try to lookup nodes from cache in if the user
  has less than 10 nodes available.

* Add tests for the opportunistic proxy node lookup

* Apply suggestions from code review

* Update lib/ai/client.go
2023-08-09 18:21:08 +00:00
Hugo Shaka 915299a04b
assist: add classification code and emit even on execution (#28492) 2023-07-26 15:35:24 +00:00
Hugo Shaka 2b15263e49
assist: Refactor token counting (#29224)
With the actor model, tokens can be used in multiple ways (picking
tools, invoking them, ...), which don't necessarily end up in a final
action (sometimes we return a nextStep instead). Streaming responses
were another challenge: the agent returned without the completion being
over (it returned a routine streaming the deltas sent by the model).

This PR introduces a TokenCounter interface that abstracts synchronous
and asynchronous token counting. All token-consuming operations must
return a TokenCounter. TokensCounters are stored in the agent state and
returned once the agent exists. Finally, the token counters are
evaluated asynchronously to give the streaming completion requests
enough time to finish.
2023-07-21 21:43:53 +00:00
Hugo Shaka 2077868d08
assist: support recording non-interactive forwarded sessions (#28677)
* assist: support recording non-interactive forwarded sessions

* assist: add integration tests for assist command recording on agentless

This also fixes a bugged openssh integration test check.

* Mock OpenAI API in integration tests.

Also fixes the OpenAI mock handler that was not supporting the "/v1/*"
routes used in some web/ tests.

* Docstrings + adressing again a feedback that got lost during a rebase

* restore signer function signature

* Address Jakub's feedback + diverse improvements

- improve comments
- simpler file creation
- more efficient rsa key generation
- use assert instead of require in other goroutines
- only save env vars if they are Teleport-related
- move more logic into newTestCredentials for readability

* Update lib/srv/forward/sshserver.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Add a timeout in the ssh handler coroutine

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2023-07-14 15:03:57 +00:00
Jakub Nyckowski f13cd935a9
Set lower temperature to ChatGPT calls (#28793)
Updated the ChatCompletionRequest in the agent model to include temperature parameter. The temperature parameter controls the randomness of the AI's responses, making the model more conservative and focused with a lower value. In this case, the temperature is set to 0.3 to produce more focused and consistent results. Default is 1.0. Max is 2.0.
2023-07-11 17:20:08 +00:00
Joel 490d9d6030
[Assist] Provide interactive updates during agent execution (#27893)
* send progress update messages during agent thoughts

* handle new output format

* define json tags for serialized fields

* use streaming api

* fan streaming from model loop

* fix streaming

* stream progress updates

* Update lib/assist/assist.go

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>

* remove useless mute

* nits

* Update lib/ai/model/agent.go

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>

* fix merge

* fix misc

* more misc fixes

* what

* what2

* weird eof errors?

* Fix tests UI integration

* Fix other tests

* Linter fixes

* Comment out token counting for assist streams to avoid race condition.

* Fix more tests

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
2023-07-03 14:48:06 +00:00
Hugo Shaka 303aada16a
assist: add classification code (#28221) 2023-06-30 19:25:15 +00:00
Jakub Nyckowski c9bf80be65
Improve error handling and embedding prompts; fix typos (#28403)
* "Improve error handling and embedding prompts; fix typos"

This commit encompasses several changes. First, an error handling routine has been added in AssistContext.tsx to properly close a WebSocket connection and finish all results. The intent is to ensure that execution fails gracefully when a session doesn't end normally. In tool.go, user instructions have been made more explicit to ensure users check access to nodes before generating any commands. It warns them that not checking access will cause error. Also, some minor typos were corrected in agent.go and messages.go for better readability.

* "Refactor 'hosts' to 'nodes' in AI Tool Descriptions"

This commit refactors the language from 'host' terminology to 'node' terminology in the AI tool's generated responses as the LLM seems to be confused when generating queries with embeddings.

* Update expected test values in chat_test.go

The expected values in three different tests in chat_test.go have been updated. This change was required because the underlying algorithm has been adjusted and these modifications will keep the tests aligned with the current algorithm's behavior.
2023-06-29 14:41:39 +00:00
Jakub Nyckowski 2b0fb80733
[Assist] Include embeddings in the prompt (#28116)
* [Assist] Include embeddings in the prompt

* Add comments
GCI
Minor fixes

* Move stuff

* Fix tests

* Fix tests

* Fixes after rebase
Apply code review suggestions.

* Address review comments

* After rebase fix
2023-06-27 20:57:20 +00:00
Hugo Shaka d386c422eb
ai: compute opportinistic summary of command execution (#28033)
* ai: compute opportinistic summary of command execution

* ai: add streaming summary back after rebase on new front-end

* Lint and fix tests pt.1

* reference nodes by name and add tests

* Lint, fix tests and address feedback

* Attempt to tame the stream close monster

* fixup! Attempt to tame the stream close monster

* [Assist] Do not close the WS after command execution (#28246)

* Revert "fixup! Attempt to tame the stream close monster"

This reverts commit 8537aa2163.

* Revert "Attempt to tame the stream close monster"

This reverts commit e0c861df40.

* Do not close the WS after command execution

* Fix tests and lint

* fixup! Fix tests and lint

* undo put web test command into constant

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
2023-06-27 16:14:03 +00:00
Jakub Nyckowski 92e5f47695
Restore lib/ai tests (#28077)
* Restore `lib/ai` tests

The tests were removed as a part of https://github.com/gravitational/teleport/pull/27075.

This PR updates the tests to use the new logic.

* Fix tests

* Restore lib/web tests

* GCI

* Move test handler to a common place

* Fix used token test

* Add comment
2023-06-21 20:36:51 +00:00
Hugo Shaka c326b8c3ef
ai: Add a node embedding watcher (#27204)
* ai: add embeddings basic support

- add Embeddings service and its local implementation
- add Embedding type and proto message
- add nodeEmbeddingCollector tracking nodes
- add NodeEmbeddingWatcher watching for events adn sending them to the
  collector
- add the Embedder interface and its openai implementation

* ai: adapt embeddings to the vector index

* fixup! ai: adapt embeddings to the vector index

* fixup! fixup! ai: adapt embeddings to the vector index

* Update lib/service/service.go

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>

* address feedback pt.1

* address feedback pt.2: store protobuf message in backend

* address feedback pt.3: have GetEmbeddings return a stream

* Update lib/services/embeddings.go

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>

* address feedback pt.4: extract embedding logic out of Embeddings service

* fixup! address feedback pt.4: extract embedding logic out of Embeddings service

* address feedback pt.5: simpler error handling when embedding fails

* fix tests pt.1

* fix tests pt.2

* fix tests pt.3

* [Assist] Replace embedding watcher (#27953)

Change the way how the embeddings are calculated. Instead of creating a watcher in Auth, we will process all nodes every hour and process embeddings if any embeddings are missing or any node has been updated.

---------

Co-authored-by: Jakub Nyckowski <jakub.nyckowski@goteleport.com>
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>
2023-06-21 01:28:56 +00:00
Joel 36dcc6bc72
[Assist] Scaffold the chat-loop onto a multi-step thinking model (#27075)
* agent scaffold conversion

* command input validation

* rename Agent.Think and replace debug logs with trace logs

* doc

* action docs

* godocs

* clarify

* remove unused code

* remove tests which relied on the old non-agent model interaction with the llm

* fix broken e
2023-06-08 14:15:29 +00:00
Jakub Nyckowski cd6b091a46
Return errors over Assist WS (#27174)
* Return errors over Assist WS

* Add test

* Address code review comments
Add check for the close message in assist WS

* Use UTC for getting time
2023-06-07 22:07:15 +00:00
Jakub Nyckowski 36f9bd3516
Implement in-memory vector DB (#27329)
In order to include embeddings in the Assist conversations, we need a way to store and retrieve when needed. This PR adds vector store/search implementation based on k-d tree.
2023-06-07 14:47:46 +00:00
Mike Jensen 7f331a5f11
Rename ChatGPT to GPT-4 (#26272)
* Rename `ChatGPT` to `GPT4`

ChatGPT is a user friendly name, but is technically inaccurate.

* Apply suggestions from code review

Co-authored-by: Reed Loden <reed@goteleport.com>

* Lint fix

* Additional ChatGPT --> OpenAI GPT-4 fixes

---------

Co-authored-by: Reed Loden <reed@goteleport.com>
2023-05-16 06:20:22 +00:00
Jakub Nyckowski 5fddd75d0f
Assist - Web endpoints (#26046)
* Assist - Web endpoints

* GCI

* proto rpc

* enforce endpoint checks

* disable in ui if disallowed by auth

* add comment

* unwrap stack

* Refactor code

---------

Co-authored-by: Joel Wejdenstål <jwejdenstal@icloud.com>
2023-05-13 05:00:44 +00:00
Jakub Nyckowski 60c01faa42
Assist - OpenAI library port (#25948)
* Assist - OpenAI library port

* Add tests

* Address code review comments

* Added comment

* Partial backport of https://github.com/gravitational/teleport/pull/26058

* Move AI messages to a new file

* Prevent blocking on error

* Add comments.
Fix typo
2023-05-11 17:33:42 +00:00