-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix environment factory test (pytype issue)
PiperOrigin-RevId: 696216987 Change-Id: Ic3e7c32f2bc7c326966f70f7674dd8cc2ad850a9
- Loading branch information
1 parent
0151181
commit 3a7cc99
Showing
5 changed files
with
74 additions
and
54 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2023 DeepMind Technologies Limited. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Json helper functions.""" | ||
|
||
import json | ||
|
||
from concordia.agents import entity_agent_with_logging | ||
from concordia.typing import entity_component | ||
|
||
|
||
def save_to_json( | ||
agent: entity_agent_with_logging.EntityAgentWithLogging, | ||
) -> str: | ||
"""Saves an agent to JSON data. | ||
This function saves the agent's state to a JSON string, which can be loaded | ||
afterwards with `rebuild_from_json`. The JSON data | ||
includes the state of the agent's context components, act component, memory, | ||
agent name and the initial config. The clock, model and embedder are not | ||
saved and will have to be provided when the agent is rebuilt. The agent must | ||
be in the `READY` phase to be saved. | ||
Args: | ||
agent: The agent to save. | ||
Returns: | ||
A JSON string representing the agent's state. | ||
Raises: | ||
ValueError: If the agent is not in the READY phase. | ||
""" | ||
|
||
if agent.get_phase() != entity_component.Phase.READY: | ||
raise ValueError('The agent must be in the `READY` phase to be saved.') | ||
|
||
data = { | ||
component_name: agent.get_component(component_name).get_state() | ||
for component_name in agent.get_all_context_components() | ||
} | ||
|
||
data['act_component'] = agent.get_act_component().get_state() | ||
|
||
config = agent.get_config() | ||
if config is not None: | ||
data['agent_config'] = config.to_dict() | ||
|
||
return json.dumps(data) |