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

fix(core): consistently generated session ids #531

Merged
merged 12 commits into from
Oct 8, 2024
Prev Previous commit
Next Next commit
add: minor changes
Archento committed Oct 8, 2024
commit d223be10a86646e6bf4778612447a525fd4ef786
18 changes: 12 additions & 6 deletions python/src/uagents/agent.py
Original file line number Diff line number Diff line change
@@ -82,7 +82,8 @@ async def _run_interval(

Args:
func (IntervalCallback): The interval callback function to run.
agent (Agent): The agent that is running the interval callback.
logger (logging.Logger): The logger instance for logging interval handler activities.
context_factory (ContextFactory): The factory function for creating the context.
period (float): The time period at which to run the callback function.
"""
while True:
@@ -419,9 +420,10 @@ async def _handle_get_messages(_ctx: Context):

def _build_context(self) -> InternalContext:
"""
An internal method to build the context for the agent
An internal method to build the context for the agent.

@return:
Returns:
InternalContext: The internal context for the agent.
"""
return InternalContext(
agent=AgentRepresentation(
@@ -1009,8 +1011,8 @@ async def handle_rest(
if not handler:
return None

context = self._build_context()
args = [context]
args = []
args.append(self._build_context())
if message:
args.append(message)

@@ -1184,7 +1186,11 @@ async def _process_message_queue(self):
)

context = ExternalContext(
agent=self,
agent=AgentRepresentation(
address=self.address,
name=self._name,
signing_callback=self._identity.sign_digest,
),
storage=self._storage,
ledger=self._ledger,
resolver=self._resolver,
3 changes: 1 addition & 2 deletions python/src/uagents/context.py
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ class Context(ABC):
storage (KeyValueStore): The key-value store for storage operations.
ledger (LedgerClient): The client for interacting with the blockchain ledger.
logger (logging.Logger): The logger instance.
session (uuid.UUID): The session UUID associated with the context.

Methods:
get_agents_by_protocol(protocol_digest, limit, logger): Retrieve a list of agent addresses
@@ -563,7 +564,6 @@ class ExternalContext(InternalContext):
Attributes:
_queries (Dict[str, asyncio.Future]): Dictionary mapping query senders to their
response Futures.
_session (Optional[uuid.UUID]): The session UUID.
_replies (Optional[Dict[str, Dict[str, Type[Model]]]]): Dictionary of allowed reply digests
for each type of incoming message.
_message_received (Optional[MsgDigest]): The message digest received.
@@ -586,7 +586,6 @@ def __init__(
message_received (MsgDigest): The optional message digest received.
queries (Dict[str, asyncio.Future]): Dictionary mapping query senders to their
response Futures.
session (Optional[uuid.UUID]): The optional session UUID.
replies (Optional[Dict[str, Dict[str, Type[Model]]]]): Dictionary of allowed replies
for each type of incoming message.
protocol (Optional[Tuple[str, Protocol]]): The optional Tuple of protocols.