-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Feat: ReAct #3998
Open
phact
wants to merge
50
commits into
langflow-ai:main
Choose a base branch
from
phact:react
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat: ReAct #3998
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
e94ba5b
fixes and integrations tests
phact 518d571
WIP
phact ed6a71d
Set `_has_cycle_edges` to `True` for source and target vertices in cy…
ogabrielluiz 8279f98
feat: Add `has_cycle_edges` method to Vertex class
ogabrielluiz 7973cf3
Add `apply_on_outputs` method to Vertex for applying functions to out…
ogabrielluiz 4a81005
Add utility to find vertices in cycles within a directed graph
ogabrielluiz 0363278
Add unit tests for `find_cycle_vertices` utility function in graph mo…
ogabrielluiz bfaafc9
Add method to set cache for vertices in cycle
ogabrielluiz b4e1471
refactor: Update caching logic for vertices in cycles
ogabrielluiz 0ea18d4
Refactor `find_cycle_vertices` to use NetworkX for cycle detection
ogabrielluiz f30a402
Refactor `find_cycle_vertices` tests to remove entry point parameter …
ogabrielluiz 3aaf6f4
Disable cache in cycle: Update `apply_on_outputs` to handle empty out…
ogabrielluiz 0af95c9
Add unit test to ensure output cache is disabled in graph cycles
ogabrielluiz bf5e834
Add unit test for graph cyclicity with prompt components and OpenAI i…
ogabrielluiz 832d5cd
Convert `_instantiate_components_in_vertices` to async and disable ca…
ogabrielluiz 78853cb
Add default value handling for cycle edges in vertex component
ogabrielluiz b375612
Switch from os.environ to os.getenv for API key retrieval in test_cyc…
ogabrielluiz a2bfdc8
Add __repr__ method to Edge class to indicate cycle edges with a symbol
ogabrielluiz 35fe1bd
Refactor test_cycles.py to streamline component initialization and up…
ogabrielluiz 55a7346
Refactor test_cycles.py to streamline component initialization and up…
ogabrielluiz a99808b
Refactor test to use custom serialization method instead of pickle
ogabrielluiz 9f6de69
Add cycle_vertices property to optimize cycle detection in graph
ogabrielluiz 88b2c9a
Enhance error message in `types.py` to include component ID for bette…
ogabrielluiz 3d2e207
Refactor test_cycles.py to update graph configuration and assertions
ogabrielluiz 31ff469
Add api_key_required marker to test_updated_graph_with_prompts test
ogabrielluiz 46b9588
Add validation to require max_iterations for cyclic graphs
ogabrielluiz ee84cf5
merge
phact b8c6809
missed >>>>
phact 8a132d5
dynamic tool selection
phact e0e38c0
pass thread and assistant ids
phact 49f8d3b
react initial take
phact 0ad0129
merge assistant-manager into react branch
phact 02afb5b
Merge branch 'main' into feat/disablecacheincycle
ogabrielluiz 45f5c07
ReAct test
phact 7b6757e
merge
phact 5fc6f98
back out inputs.py change
phact 5eb4ad4
back out inputs.py change
phact ffd64f0
add shared component cache
phact 1844202
merge
phact e452c4f
uv.lock
phact 186a5cd
[autofix.ci] apply automated fixes
autofix-ci[bot] 0604dc6
some ruff style fixes
phact cf28a6f
Merge branch 'react' of github.com:phact/langflow into react
phact 6de5704
INP001
phact 21da797
Update src/backend/base/langflow/services/shared_component_cache/fact…
phact cb49a7d
Update src/backend/base/langflow/services/shared_component_cache/serv…
phact 051354a
[autofix.ci] apply automated fixes
autofix-ci[bot] 66765da
make the cache private, fix service/factory
phact 29880f9
[autofix.ci] apply automated fixes
autofix-ci[bot] d8c3509
Merge branch 'langflow-ai:main' into react
phact File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/backend/base/langflow/components/astra_assistants/astra_assistant_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import asyncio | ||
|
||
from astra_assistants.astra_assistants_manager import AssistantManager | ||
|
||
from langflow.components.astra_assistants.util import ( | ||
get_patched_openai_client, | ||
litellm_model_names, | ||
tool_names, | ||
tools_and_names, | ||
) | ||
from langflow.custom.custom_component.component_with_cache import ComponentWithCache | ||
from langflow.inputs import DropdownInput, MultilineInput, StrInput | ||
from langflow.schema.message import Message | ||
from langflow.template import Output | ||
|
||
|
||
class AstraAssistantManager(ComponentWithCache): | ||
display_name = "Astra Assistant Manager" | ||
description = "Manages Assistant Interactions" | ||
icon = "bot" | ||
|
||
inputs = [ | ||
StrInput( | ||
name="instructions", | ||
display_name="Instructions", | ||
info="Instructions for the assistant, think of these as the system prompt.", | ||
), | ||
DropdownInput( | ||
name="model_name", | ||
display_name="Model Name", | ||
advanced=False, | ||
options=litellm_model_names, | ||
value="gpt-4o-mini", | ||
), | ||
DropdownInput( | ||
display_name="Tool", | ||
name="tool", | ||
options=tool_names, | ||
), | ||
MultilineInput( | ||
name="user_message", | ||
display_name="User Message", | ||
info="User message to pass to the run.", | ||
), | ||
MultilineInput( | ||
name="input_thread_id", | ||
display_name="Thread ID (optional)", | ||
info="ID of the thread", | ||
), | ||
MultilineInput( | ||
name="input_assistant_id", | ||
display_name="Assistant ID (optional)", | ||
info="ID of the assistant", | ||
), | ||
MultilineInput( | ||
name="env_set", | ||
display_name="Environment Set", | ||
info="Dummy input to allow chaining with Dotenv Component.", | ||
), | ||
] | ||
|
||
outputs = [ | ||
Output(display_name="Assistant Response", name="assistant_response", method="get_assistant_response"), | ||
Output(display_name="Tool output", name="tool_output", method="get_tool_output"), | ||
Output(display_name="Thread Id", name="output_thread_id", method="get_thread_id"), | ||
Output(display_name="Assistant Id", name="output_assistant_id", method="get_assistant_id"), | ||
] | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self.lock = asyncio.Lock() | ||
self.initialized = False | ||
self.assistant_response = None | ||
self.tool_output = None | ||
self.thread_id = None | ||
self.assistant_id = None | ||
self.client = get_patched_openai_client(self._shared_component_cache) | ||
|
||
async def get_assistant_response(self) -> Message: | ||
await self.initialize() | ||
return self.assistant_response | ||
|
||
async def get_tool_output(self) -> Message: | ||
await self.initialize() | ||
return self.tool_output | ||
|
||
async def get_thread_id(self) -> Message: | ||
await self.initialize() | ||
return self.thread_id | ||
|
||
async def get_assistant_id(self) -> Message: | ||
await self.initialize() | ||
return self.assistant_id | ||
|
||
async def initialize(self): | ||
async with self.lock: | ||
if not self.initialized: | ||
await self.process_inputs() | ||
self.initialized = True | ||
|
||
async def process_inputs(self): | ||
print(f"env_set is {self.env_set}") | ||
print(self.tool) | ||
tools = [] | ||
tool_obj = None | ||
if self.tool is not None and self.tool != "": | ||
tool_cls = tools_and_names[self.tool] | ||
tool_obj = tool_cls() | ||
tools.append(tool_obj) | ||
assistant_id = None | ||
thread_id = None | ||
if self.input_assistant_id: | ||
assistant_id = self.input_assistant_id | ||
if self.input_thread_id: | ||
thread_id = self.input_thread_id | ||
assistant_manager = AssistantManager( | ||
instructions=self.instructions, | ||
model=self.model_name, | ||
name="managed_assistant", | ||
tools=tools, | ||
client=self.client, | ||
thread_id=thread_id, | ||
assistant_id=assistant_id, | ||
) | ||
|
||
content = self.user_message | ||
result = await assistant_manager.run_thread(content=content, tool=tool_obj) | ||
self.assistant_response = Message(text=result["text"]) | ||
if "decision" in result: | ||
self.tool_output = Message(text=str(result["decision"].is_complete)) | ||
else: | ||
self.tool_output = Message(text=result["text"]) | ||
self.thread_id = Message(text=assistant_manager.thread.id) | ||
self.assistant_id = Message(text=assistant_manager.assistant.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
src/backend/base/langflow/components/astra_assistants/list_assistants.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ideally, the tools would be Components.
What if these tools work as default ones?
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.
Maybe there's a way to do both, pick from the dropdown if the tools are simple and don't have any configuration or add an edge from a component for more complex tools. We would probably also want a way to accept langchain basetool tools for assistants dynamically.
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.
You should also be able to pass more than one tool and let it decide which to use. Is there a multi-select input in langflow?