pass a returned file from a function to another function with agent #5238
Unanswered
Zohreh6384NKH
asked this question in
Q&A
Replies: 3 comments 10 replies
-
I am not sure what's the blocker here is? You can call one agent to list the files, and then call other agent to read the files. Or, having the same agent with both tools, and call the agent twice. Could you describe a bit more what is the context and scenario? By just reading the description it feels like this should be accomplished by just calling two agents or one agent two times. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Hi Eric . I tried to use sequential chat but still I can only receive the
dictionary of python files which is the first step. for the second step I
should somehow give this dictionary and pass it through another agent to
call read_file_content but it can not get. here is my code could you tell
me what is the problem with my prompt:
…On Tue, Jan 28, 2025 at 10:50 PM Eric Zhu ***@***.***> wrote:
@Zohreh6384NKH <https://github.com/Zohreh6384NKH> I believe group chat is
a wrong choice for your scenario. You have deterministic sequence of steps,
but group chat cannot provide that deterministic sequence as it uses an LLM
to choose the next step.
f"Please follow these steps sequentially:\n"
If your steps are sequential, why using group chat?
What will work well for you, is to call each agent in sequence manually,
and pass relevant chat history as context from one agent to the next one.
Group chat is for handling ad-hoc scenarios when for each task, the steps
are decided on the fly. This is similar to a single agent with all the
tools -- the order of tool invocation is different for different tasks. If
you have such scenario, choose GroupChat. You can add some determinism by
using a selector function.
I can see you are using an outdated v0.2 API. I highly recommend upgrading
to v0.4. Make sure you install autogen-agentchat~=0.4.0 to upgrade your
AutoGen.
—
Reply to this email directly, view it on GitHub
<#5238 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFLSJZJHIQPVIPSUD5F526L2NACSJAVCNFSM6AAAAABWBFV372VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCOJYHE3TGOA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
6 replies
-
Thanks Eric . I just wanted to do it in an agentic workflow. Now that I
have the content of the files, do you think for extracting helper functions
in a code I can create a conversable agent that does the task for me?
…On Wed, Jan 29, 2025 at 5:19 PM Eric Zhu ***@***.***> wrote:
@Zohreh6384NKH <https://github.com/Zohreh6384NKH> I believe you shouldn't
be using AI agents. Use VSCode + GitHub Copilot I can quickly generate the
following code that does what you want, 100 % of the time.
import osimport tempfilefrom typing import Dict, List
def list_python_files_by_directory(dir: str) -> Dict[str, List[str]]:
""" Get all the python files in the given directory, grouped by the directory they are in. """
python_files = dict()
for root, _, files in os.walk(dir):
python_files[root] = [file for file in files if file.endswith(".py")]
return python_files
def read_files_content(files: Dict[str, List[str]]) -> Dict[str, str]:
""" Reads the content of the given files and returns a dictionary with the full file name as the key and the content as the value. """
files_content = dict()
for directory, files in files.items():
for file in files:
with open(os.path.join(directory, file), "r") as f:
files_content[os.path.join(directory, file)] = f.read()
return files_content
if __name__ == "__main__":
with tempfile.TemporaryDirectory() as tmpdirname:
print(f"Created temporary directory: {tmpdirname}")
# Put some files in the temporary directory
with open(os.path.join(tmpdirname, "file1.py"), "w") as f:
f.write("print('Hello, World!')")
with open(os.path.join(tmpdirname, "file2.py"), "w") as f:
f.write("print('Hello, Python!')")
python_files = list_python_files_by_directory(tmpdirname)
files_content = read_files_content(python_files)
for file, content in files_content.items():
print(f"File: {file}\nContent:\n{content}\n")
Maybe you can add a prompting step at the end just to get some natural
language response.
—
Reply to this email directly, view it on GitHub
<#5238 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFLSJZJJF3264SHG7T64VL32NEERPAVCNFSM6AAAAABWBFV372VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCOJZHAZDANI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hi could you please help me wih this. i have a function which return a dictionary of files .now i want to get an agent to pass this dictionary to another function as input and want an agent to call the fucntion. how agent can get the output and pass it as input of another function
Beta Was this translation helpful? Give feedback.
All reactions