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

Agent tool sources #6854

Merged
merged 9 commits into from
Jul 12, 2023
Merged

Agent tool sources #6854

merged 9 commits into from
Jul 12, 2023

Conversation

logan-markewich
Copy link
Collaborator

@logan-markewich logan-markewich commented Jul 11, 2023

Description

This exposes the names, inputs, and outputs of tools called in between each agent response.

BREAKING CHANGE ALERT: Agents no longer stream intermediate steps, in order to align with chat engine behaviour.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Added new notebook (that tests end-to-end)
  • I stared at the code and made sure it makes sense

Todo:

@@ -133,20 +148,23 @@ def chat(
print(log_str)

# Query with standalone question
response = self._query_engine.query(condensed_question)
query_response = self._query_engine.query(condensed_question)
tool_output = self._get_tool_output_from_response(
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the query_response has source_nodes, this gets lost right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, it ends up in the raw_output of the tool output -> see self._get_tool_output_from_response()

Copy link
Collaborator

Choose a reason for hiding this comment

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

i see


logger = logging.getLogger(__name__)


class StreamingChatResponse:
@dataclass
class AgentChatResponse:
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this break backwards compat for existing chat engines/agents in parsing the response type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

which backwards compat are you thinking of? The only breaking change I noticed was that agents don't stream a generator of generators anymore, just a single generator for the final response

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh mostly that the existing chat engine response type was RESPONSE_TYPE, but now it's AgentChatResponse. So if the user was doing something like response.source_nodes it would break

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah yea, that is a possibility 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

could do a temporary property on AgentChatResponse called source_nodes (and try fetching raw_output.source_ndoes..., but seems hacky)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like breaking this is inevitable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

and I suspect we are probably gonna break it a couple more times as we figure out the interface.

@@ -24,7 +24,8 @@ To stream response:
```python
chat_engine = index.as_chat_engine()
streaming_response = chat_engine.stream_chat("Tell me a joke.")
streaming_response.print_response_stream()
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious: why don't we preserve this API?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we probably should!

from llama_index.memory import BaseMemory
from llama_index.types import TokenGen


def response_gen_with_chat_history(
message: str, memory: BaseMemory, response_gen: TokenGen
) -> TokenGen:
) -> Generator[ChatResponse, None, None]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Isn't this a ChatResponseGen ;)

@jerryjliu jerryjliu merged commit aa56f21 into main Jul 12, 2023
@jerryjliu jerryjliu deleted the logan/agent_tool_sources branch July 12, 2023 07:40
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