sherpa_ai.memory package#

Submodules#

sherpa_ai.memory.belief module#

class sherpa_ai.memory.belief.Belief[source]#

Bases: object

The belief of the agent. it contains
  1. events: the events observed by the agent, synchronized with the shared memory

  2. internal_events: the internal events generated by the agent through its reasoning process (actions)

property action_description#
classmethod from_dict(data)[source]#
get(key, default=None)[source]#

Get value from the dict, the key can be a dot separated string if the value is nested

get_action(action_name) BaseAction[source]#
get_actions() List[BaseAction][source]#
get_all_keys()[source]#
get_by_type(event_type)[source]#
get_context(token_counter: Callable[[str], int])[source]#

Get the context of the agent

Parameters:
  • token_counter – Token counter

  • max_tokens – Maximum number of tokens

Returns:

Context of the agent

Return type:

str

get_dict()[source]#
get_histories_excluding_types(exclude_types: list[EventType], token_counter: Callable[[str], int] | None = None, max_tokens=4000)[source]#

Get the internal history of the agent without events of excluded_type

Parameters:
  • token_counter – Token counter

  • max_tokens – Maximum number of tokens

  • exclude_types – List of events to be excluded

Returns:

Internal history of the agent with event content separated by newlines. History is truncated if the number of tokens exceeds max_tokens.

Return type:

str

get_internal_history(token_counter: Callable[[str], int])[source]#

Get the internal history of the agent

Parameters:

token_counter – Token counter

Returns:

Internal history of the agent with event content separated by newlines. History is truncated if the number of tokens exceeds max_tokens.

Return type:

str

get_state() str[source]#
get_state_obj() State[source]#
has(key)[source]#

Check if the key exists in the dict

set(key, value)[source]#

Set value in the dict, the key can be a dot separated string if the value is nested

set_actions(actions: List[BaseAction])[source]#
set_current_task(task: Event)[source]#
update(observation: Event)[source]#
update_internal(event_type: EventType, agent: str, content: str)[source]#

sherpa_ai.memory.shared_memory module#

class sherpa_ai.memory.shared_memory.SharedMemory(objective: str, agent_pool: AgentPool = None)[source]#

Bases: object

add(event_type: EventType, agent: str, content: str)[source]#
add_event(event: Event)[source]#
classmethod from_dict(data, agent_pool)[source]#
get_by_type(event_type)[source]#
observe(belief: Belief)[source]#

Module contents#

class sherpa_ai.memory.Belief[source]#

Bases: object

The belief of the agent. it contains
  1. events: the events observed by the agent, synchronized with the shared memory

  2. internal_events: the internal events generated by the agent through its reasoning process (actions)

property action_description#
classmethod from_dict(data)[source]#
get(key, default=None)[source]#

Get value from the dict, the key can be a dot separated string if the value is nested

get_action(action_name) BaseAction[source]#
get_actions() List[BaseAction][source]#
get_all_keys()[source]#
get_by_type(event_type)[source]#
get_context(token_counter: Callable[[str], int])[source]#

Get the context of the agent

Parameters:
  • token_counter – Token counter

  • max_tokens – Maximum number of tokens

Returns:

Context of the agent

Return type:

str

get_dict()[source]#
get_histories_excluding_types(exclude_types: list[EventType], token_counter: Callable[[str], int] | None = None, max_tokens=4000)[source]#

Get the internal history of the agent without events of excluded_type

Parameters:
  • token_counter – Token counter

  • max_tokens – Maximum number of tokens

  • exclude_types – List of events to be excluded

Returns:

Internal history of the agent with event content separated by newlines. History is truncated if the number of tokens exceeds max_tokens.

Return type:

str

get_internal_history(token_counter: Callable[[str], int])[source]#

Get the internal history of the agent

Parameters:

token_counter – Token counter

Returns:

Internal history of the agent with event content separated by newlines. History is truncated if the number of tokens exceeds max_tokens.

Return type:

str

get_state() str[source]#
get_state_obj() State[source]#
has(key)[source]#

Check if the key exists in the dict

set(key, value)[source]#

Set value in the dict, the key can be a dot separated string if the value is nested

set_actions(actions: List[BaseAction])[source]#
set_current_task(task: Event)[source]#
update(observation: Event)[source]#
update_internal(event_type: EventType, agent: str, content: str)[source]#
class sherpa_ai.memory.SharedMemory(objective: str, agent_pool: AgentPool = None)[source]#

Bases: object

add(event_type: EventType, agent: str, content: str)[source]#
add_event(event: Event)[source]#
classmethod from_dict(data, agent_pool)[source]#
get_by_type(event_type)[source]#
observe(belief: Belief)[source]#