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

Adding support for a new runnable for InlineAgents #340

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

divekarshubham
Copy link

@divekarshubham divekarshubham commented Jan 28, 2025

Description

This PR introduces a new Bedrock Inline-Agents Runnable that allows using InvokeInlineAgent API with return of control functions as tools and configurable agentic properties.

Usage

See Jupyter notebook for usage with AgentExecutor

Closes #309

@divekarshubham divekarshubham force-pushed the inline_agents_support branch 2 times, most recently from 10ad334 to 5f9ad6c Compare January 28, 2025 08:11
@divekarshubham divekarshubham marked this pull request as ready for review January 28, 2025 08:12
Copy link
Collaborator

@jdbaker01 jdbaker01 left a comment

Choose a reason for hiding this comment

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

Good start, I really like how inline agents fits the interfaces better than the create agent/invoke agent pattern. Left a comment on the interface itself. We should adhere to the messages input/output contract similar to how the chat models do it.

prompt_override_configuration: Optional[Dict]
inline_session_state: Optional[Dict]

class BedrockInlineAgentsRunnable(RunnableSerializable[Dict, OutputType]):
Copy link
Collaborator

Choose a reason for hiding this comment

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

The contract seems to deviate from how other Runnables are implemented. Notice here in the Anthropic Chat Model that they use message as input and output: https://github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/language_models/chat_models.py#L127

If we support message in and message out then this will easily plugin to LCEL, LG and other constructs they have.

@3coins 3coins added this to the 2025 Feb Release 2 milestone Feb 13, 2025
Copy link
Collaborator

@jdbaker01 jdbaker01 left a comment

Choose a reason for hiding this comment

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

I like this better than the state based approach. Left a comment to remove the older executor based approach.

get_boto_session,
)

class BedrockInlineAgentsChatModel(BaseChatModel):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not have both BedrockInlineAgentRunnable and BedrockInlineAgentsChatModel. Remove the state based BedrockInlineAgentRunnable implementation and rename BedrockInlineAgentsChatModel to BedrockInlineAgentRunnable. I like how the new implementation supports the standardized message interface and will integrate with LangGraph better.

Please update the inline_agent_langgraph notebook to use this implementation instead of the current state based approach. I would like use to completely remove "should_continue" just like here in this sample they have no should_continue: https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/#usage

Copy link
Author

@divekarshubham divekarshubham Feb 15, 2025

Choose a reason for hiding this comment

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

Thanks, merged the two interfaces and added a langgraph integration notebook.
We'd still need the custom parsers for running the graph because of the way RoC inputs are passed to the agent. We can investigate more on how to handle this natively within the runnable itself in next iterations.

response_text = json.dumps(event)
break

if "chunk" in event:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -609,3 +311,219 @@ def _parse_intermediate_steps(
return session_id, session_state

return None, None

class BedrockInlineAgentsRunnable(BaseChatModel):
Copy link
Collaborator

@3coins 3coins Feb 20, 2025

Choose a reason for hiding this comment

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

What was the motivation behind using the ChatModel as base rather than a Runnable/RunnableSerializable?

ChatModel have specific mechanisms, for example bind_tools to work with tools, that this implementation will bypass, so this might not be the right interface for the agents.

session_id = response["sessionId"]
trace_log_elements = []
files = []
for event in event_stream:

Choose a reason for hiding this comment

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

Should we have some sort of signal for unknown event types so consumers can more easily identify service model changes?

Copy link
Author

Choose a reason for hiding this comment

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

Currently this is not a type within the response, will investigate more and update this in a later PR

)
]
except Exception as ex:
raise Exception("Parse exception encountered {}".format(repr(ex)))

Choose a reason for hiding this comment

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

Is there an exception hierarchy that we can add onto here? Exception is broad.

Copy link
Author

Choose a reason for hiding this comment

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

Unsure of this one, keeping it broad to encompass all validation + serviceUnavailable exceptions.

@3coins
Copy link
Collaborator

3coins commented Feb 22, 2025

@divekarshubham
Can you rebase from main and submit again?

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.

Bedrock Inline Agents and Code Interpreter
4 participants