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

Implement context-aware agent functionality. #1394

Merged
merged 3 commits into from
Oct 26, 2024

Conversation

erik-balfe
Copy link
Contributor

Context-Aware Agent Implementation

This PR introduces context-awareness functionality for agents, inspired by the discussion in #1224.

Implementation:

  • Added withContextAwareness mixin in contextAwareMixin.ts
  • Created OpenAIContextAwareAgent and AnthropicContextAwareAgent
  • Updated relevant documentation and examples

Motivation:

The goal is to allow agents to access indexed data without explicitly calling retriever tools, reducing latency in real-time scenarios especially with not so fast LMs. This approach is analogous to the ContextChatEngine, which automatically incorporates retriever data into the chat context.

Approach:

The implementation uses a mixin pattern to add context retrieval and injection capabilities to existing agent classes. This method allows for flexibility and easy extension to different agent types.

Feedback on the implementation approach and any potential improvements is welcome.

Just recreated branch and PR (old one: #1235) because of conflicts in prev version. All modules were moved to core after that PR was been created. So its easier to create a new one.

Copy link

changeset-bot bot commented Oct 25, 2024

🦋 Changeset detected

Latest commit: 67d2300

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
llamaindex Minor
@llamaindex/core Minor
docs Patch
@llamaindex/autotool Major
@llamaindex/experimental Patch
@llamaindex/cloudflare-worker-agent-test Patch
@llamaindex/next-agent-test Patch
@llamaindex/nextjs-edge-runtime-test Patch
@llamaindex/next-node-runtime-test Patch
@llamaindex/waku-query-engine-test Patch
@llamaindex/autotool-01-node-example Patch
@llamaindex/autotool-02-next-example Patch
@llamaindex/cloud Major
@llamaindex/community Patch
@llamaindex/anthropic Patch
@llamaindex/clip Patch
@llamaindex/deepinfra Patch
@llamaindex/huggingface Patch
@llamaindex/ollama Patch
@llamaindex/openai Patch
@llamaindex/portkey-ai Patch
@llamaindex/replicate Patch
@llamaindex/llama-parse-browser-test Patch
@llamaindex/groq Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
legacy-llama-index-ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 26, 2024 2:01pm
llama-index-ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 26, 2024 2:01pm
llamaindex-ts-doc-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 26, 2024 2:01pm

Copy link

pkg-pr-new bot commented Oct 25, 2024

Open in Stackblitz

@llamaindex/autotool

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/autotool@1394

@llamaindex/cloud

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/cloud@1394

@llamaindex/community

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/community@1394

@llamaindex/core

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/core@1394

@llamaindex/env

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/env@1394

@llamaindex/experimental

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/experimental@1394

llamaindex

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/llamaindex@1394

@llamaindex/wasm-tools

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/wasm-tools@1394

@llamaindex/anthropic

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/anthropic@1394

@llamaindex/clip

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/clip@1394

@llamaindex/deepinfra

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/deepinfra@1394

@llamaindex/groq

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/groq@1394

@llamaindex/huggingface

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/huggingface@1394

@llamaindex/ollama

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/ollama@1394

@llamaindex/openai

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/openai@1394

@llamaindex/portkey-ai

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/portkey-ai@1394

@llamaindex/replicate

pnpm add https://pkg.pr.new/run-llama/LlamaIndexTS/@llamaindex/replicate@1394

commit: 67d2300

Copy link
Member

@himself65 himself65 left a comment

Choose a reason for hiding this comment

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

overall LGTM, just need some type improve

packages/llamaindex/src/agent/contextAwareMixin.ts Outdated Show resolved Hide resolved
packages/llamaindex/src/agent/contextAwareMixin.ts Outdated Show resolved Hide resolved
packages/llamaindex/src/agent/anthropic.ts Outdated Show resolved Hide resolved
@erik-balfe
Copy link
Contributor Author

@himself65 About all the comments above.

There’s a TypeScript error:
A mixin class must have a constructor with a single rest parameter of type 'any[]'.
(See the issue here (microsoft/TypeScript#37142)).

I believe it’s currently impossible to implement this correctly with all the necessary types while extending base LLMAgent or AgentRunner classes.

The simple approach that should work doesn’t function as intended in TypeScript, unfortunately.

In latest version I have rewritten the code using a less general approach that works with OpenaiAgent and AnthropicAgent, along with some other workarounds, but without using 'any'.

@himself65
Copy link
Member

nice work

erik-balfe and others added 3 commits October 26, 2024 17:55
- Add ContextAwareAgent mixin for retrieval capabilities for agents
- Add contextAware openai agent and anthropic agent
- Update agent guide about RAG with context aware agent example
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.

2 participants