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

What is the current way to export an thread and preload a chat with a team in v0.4 #4327

Closed
bih opened this issue Nov 23, 2024 · 5 comments · Fixed by #4730
Closed

What is the current way to export an thread and preload a chat with a team in v0.4 #4327

bih opened this issue Nov 23, 2024 · 5 comments · Fixed by #4730
Labels
awaiting-op-response Issue or pr has been triaged or responded to and is now awaiting a reply from the original poster proj-agentchat

Comments

@bih
Copy link

bih commented Nov 23, 2024

I'm fairly new to the AutoGen project and we're exploring it for our use case, but as I was prototyping it in a notebook I was wondering what is the way for us to be able to export a chat and preload it in a team. For example:

team = SelectorGroupChat(
    participants=[customer_service_agent, manager_agent, finance_agent],
    allow_repeated_speaker=False,
    model_client=OpenAIChatCompletionClient(model="gpt-4o"),
)

I can do this to get the conversation history

conversation = await team.run(task="Hello I would like a refund!")
print(conversation.messages)

But I would love to be able to export it as JSON

import json

conversation = await team.run(task="Hello I would like a refund!")
print(json.dumps(conversation.messages))

And equally I would love to be able to import the conversation history JSON so anything ran against in team.run()

conversation_history = json.loads(conversation_history_json)
conversation = await team.run(conversation=conversation_history, task="Hi world!")

Also, is it possible to message the agents with nothing (ideally as a specific flag)? We would love to be able to have agents give a meaningful intro message, but this isn't critical - we can build workarounds for this.

Note that this is for the v0.4 release!

@victordibia
Copy link
Collaborator

victordibia commented Nov 23, 2024

Hi @bih ,

We are currently working a memory interface that should help with this for the high level AgentChat API.
These capabilities are being tracked in issue #4039 and #4100 .
Stay tuned.

@bih
Copy link
Author

bih commented Nov 23, 2024

Sounds good, thanks for the quick response!

@victordibia
Copy link
Collaborator

Hi @bih ,

We have the PR for loading/saving state merged into main (should be available in the next dev release).

Documentation page is here

Save state ..

# Define a team.
assistant_agent = AssistantAgent(
    name="assistant_agent",
    system_message="You are a helpful assistant",
    model_client=OpenAIChatCompletionClient(
        model="gpt-4o-2024-08-06",
    ),
)
agent_team = RoundRobinGroupChat([assistant_agent], termination_condition=MaxMessageTermination(max_messages=2))

# Run the team and stream messages to the console.
stream = agent_team.run_stream(task="Write a beautiful poem 3-line about lake tangayika")

# Use asyncio.run(...) when running in a script.
await Console(stream)

# Save the state of the agent team.
team_state = await agent_team.save_state()

load team state

print(team_state)

# Load team state.
await agent_team.load_state(team_state)
stream = agent_team.run_stream(task="What was the last line of the poem you wrote?")
await Console(stream)

Let us know if it works for you.

@victordibia victordibia added the awaiting-op-response Issue or pr has been triaged or responded to and is now awaiting a reply from the original poster label Dec 5, 2024
@zzzzxcshuijiao
Copy link

If load_state work in anther context, how can i get the agent_team instance? In the same context, i don't need get team instance by load_state method

@victordibia
Copy link
Collaborator

victordibia commented Dec 17, 2024

Does this work for you / answer your question?

  • Run your team
  • save_state ..
  • persist to json file ...

In new context

  • create your team
  • load state (from file on disc)
  • proceed ...
import json


## save state to disk 
with open("coding/team_state.json", "w") as f:
    json.dump(team_state, f)

## load state from disk
with open("coding/team_state.json", "r") as f:
    team_state = json.load(f)

## create team
new_agent_team = RoundRobinGroupChat([assistant_agent], termination_condition=MaxMessageTermination(max_messages=2)) 

## load state
await new_agent_team.load_state(team_state)
stream = new_agent_team.run_stream(task="What was the last line of the poem you wrote?") 
await Console(stream)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-op-response Issue or pr has been triaged or responded to and is now awaiting a reply from the original poster proj-agentchat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants