-
Notifications
You must be signed in to change notification settings - Fork 184
feat: Use selected LlamaCloud index in multi-agent template #350
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Use selected LlamaCloud index in multi-agent template |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,19 @@ | |
from typing import List | ||
|
||
from app.agents.single import FunctionCallingAgent | ||
from app.engine.index import get_index | ||
from app.engine.index import IndexConfig, get_index | ||
from app.engine.tools import ToolFactory | ||
from llama_index.core.chat_engine.types import ChatMessage | ||
from llama_index.core.tools import QueryEngineTool, ToolMetadata | ||
|
||
|
||
def _create_query_engine_tool() -> QueryEngineTool: | ||
def _create_query_engine_tool(params=None) -> QueryEngineTool: | ||
""" | ||
Provide an agent worker that can be used to query the index. | ||
""" | ||
index = get_index() | ||
# Add query tool if index exists | ||
index_config = IndexConfig(**(params or {})) | ||
index = get_index(index_config) | ||
if index is None: | ||
return None | ||
top_k = int(os.getenv("TOP_K", 0)) | ||
|
@@ -31,13 +33,13 @@ def _create_query_engine_tool() -> QueryEngineTool: | |
) | ||
|
||
|
||
def _get_research_tools() -> QueryEngineTool: | ||
def _get_research_tools(**kwargs) -> QueryEngineTool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct return type annotation in The function returns a list of Apply this diff to fix the return type annotation: -from typing import List
+from typing import List, Dict, Optional
-def _get_research_tools(**kwargs) -> QueryEngineTool:
+def _get_research_tools(**kwargs) -> List[QueryEngineTool]:
|
||
""" | ||
Researcher take responsibility for retrieving information. | ||
Try init wikipedia or duckduckgo tool if available. | ||
""" | ||
tools = [] | ||
query_engine_tool = _create_query_engine_tool() | ||
query_engine_tool = _create_query_engine_tool(**kwargs) | ||
if query_engine_tool is not None: | ||
tools.append(query_engine_tool) | ||
researcher_tool_names = ["duckduckgo", "wikipedia.WikipediaToolSpec"] | ||
|
@@ -48,16 +50,17 @@ def _get_research_tools() -> QueryEngineTool: | |
return tools | ||
|
||
|
||
def create_researcher(chat_history: List[ChatMessage]): | ||
def create_researcher(chat_history: List[ChatMessage], **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add type annotations for Consider specifying the expected types within |
||
""" | ||
Researcher is an agent that take responsibility for using tools to complete a given task. | ||
""" | ||
tools = _get_research_tools() | ||
tools = _get_research_tools(**kwargs) | ||
return FunctionCallingAgent( | ||
name="researcher", | ||
tools=tools, | ||
description="expert in retrieving any unknown content or searching for images from the internet", | ||
system_prompt=dedent(""" | ||
system_prompt=dedent( | ||
""" | ||
You are a researcher agent. You are given a research task. | ||
|
||
If the conversation already includes the information and there is no new request for additional information from the user, you should return the appropriate content to the writer. | ||
|
@@ -77,6 +80,7 @@ def create_researcher(chat_history: List[ChatMessage]): | |
|
||
If you use the tools but don't find any related information, please return "I didn't find any new information for {the topic}." along with the content you found. Don't try to make up information yourself. | ||
If the request doesn't need any new information because it was in the conversation history, please return "The task doesn't need any new information. Please reuse the existing content in the conversation history." | ||
"""), | ||
""" | ||
), | ||
chat_history=chat_history, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Specify type annotations for
params
To improve code clarity and type safety, consider adding a type annotation to
params
. Since it's expected to be a dictionary of parameters, you could define it asOptional[Dict]
.Apply this diff to add the type annotation:
📝 Committable suggestion