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

feat(core): metadata handling of manifests #374

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
42 changes: 8 additions & 34 deletions integrations/fetch-ai-engine/examples/simple_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ class InitiateChitChatDialogue(Model):
pass


class AcceptChitChatDialogue(Model):
"""I accept ChitChat dialogue request"""

pass


class ChitChatDialogueMessage(DialogueMessage):
"""ChitChat dialogue message"""

Expand All @@ -41,12 +35,6 @@ class ConcludeChitChatDialogue(Model):
pass


class RejectChitChatDialogue(Model):
"""I reject ChitChat dialogue request"""

pass


# instantiate the dialogues
chitchat_dialogue = ChitChatDialogue(
version="0.1",
Expand All @@ -59,38 +47,24 @@ class RejectChitChatDialogue(Model):
print("---")


@chitchat_dialogue.on_initiate_session(InitiateChitChatDialogue)
async def start_chitchat(
ctx: Context,
sender: str,
_msg: InitiateChitChatDialogue,
):
ctx.logger.info(f"Received init message from {sender} Session: {ctx.session}")
# do something when the dialogue is initiated
await ctx.send(sender, AcceptChitChatDialogue())
@agent.on_event("startup")
async def start(ctx: Context):
print(
f"aiengine chitchat manifest: >>>>>>>>>>>>>>>>>>\n{chitchat_dialogue.manifest()}"
)


@chitchat_dialogue.on_start_dialogue(AcceptChitChatDialogue)
@chitchat_dialogue.on_start_dialogue(InitiateChitChatDialogue)
async def accepted_chitchat(
ctx: Context,
sender: str,
_msg: AcceptChitChatDialogue,
_msg: InitiateChitChatDialogue,
):
ctx.logger.info(
f"session with {sender} was accepted. This shouldn't be called as this agent is not the initiator."
)


@chitchat_dialogue.on_reject_session(RejectChitChatDialogue)
async def reject_chitchat(
ctx: Context,
sender: str,
_msg: RejectChitChatDialogue,
):
# do something when the dialogue is rejected and nothing has been sent yet
ctx.logger.info(f"Received conclude message from: {sender}")


@chitchat_dialogue.on_continue_dialogue(ChitChatDialogueMessage)
async def continue_chitchat(
ctx: Context,
Expand Down Expand Up @@ -119,7 +93,7 @@ async def conclude_chitchat(
):
# do something when the dialogue is concluded after messages have been exchanged
ctx.logger.info(f"Received conclude message from: {sender}; accessing history:")
ctx.logger.info(ctx.dialogue)
ctx.logger.info(chitchat_dialogue.get_conversation(ctx.session))


agent.include(chitchat_dialogue, publish_manifest=True)
Expand Down
87 changes: 27 additions & 60 deletions integrations/fetch-ai-engine/src/ai_engine/chitchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,18 @@
from typing import Type, Optional

from uagents import Model
from uagents.experimental.dialogues import Dialogue, Node, Edge
from uagents.storage import StorageAPI
from uagents.experimental.dialogues import Dialogue, Node

from ai_engine.dialogue import create_edge


# Node definition for the dialogue states
# Node definition for the dialogue states
default_state = Node(
name="Default State",
description=(
"This is the default state of the dialogue. Every session starts in "
"this state and is automatically updated once the dialogue starts."
),
initial=True,
)
init_state = Node(
name="Initiated",
description=(
"This is the initial state of the dialogue that is only available at "
"the receiving agent."
),
initial=True,
)
chatting_state = Node(
name="Chit Chatting",
Expand All @@ -35,49 +25,46 @@
description="This is the state after the dialogue has been concluded.",
)

# Edge definition for the dialogue transitions
init_session = create_edge(
name="Initiate session",
description="Every dialogue starts with this transition.",
target="user",
observable=True,
parent=default_state,
child=init_state,
)
reject_session = create_edge(
name="Reject dialogue",
description=("This is the transition for when the dialogue is rejected"),
target="user",
observable=True,
parent=init_state,
child=end_state,
)
start_dialogue = create_edge(

start_dialogue = Edge(
name="Start dialogue",
description="This is the transition from initiated to chit chatting.",
target="user",
observable=True,
description=(
"A message that initiates a ChitChat conversation and provides "
"any information needed to set the context and let the receiver "
"decide whether to accept or directly end this conversation."
),
parent=init_state,
child=chatting_state,
metadata={
"target": "user",
"observable": True,
},
)
cont_dialogue = create_edge(
cont_dialogue = Edge(
name="Continue dialogue",
description=(
"This is the transition from one dialogue message to the next, "
"i.e. for when the dialogue continues."
),
target="user",
observable=True,
parent=chatting_state,
child=chatting_state,
metadata={
"target": "user",
"observable": True,
},
)
end_session = create_edge(
end_session = Edge(
name="End dialogue",
description="This is the transition for when the session is ended.",
target="user",
observable=True,
description=(
"A final message that can be sent at any time by either party "
"to finish this dialogue."
),
parent=chatting_state,
child=end_state,
metadata={
"target": "user",
"observable": True,
},
)


Expand All @@ -97,14 +84,11 @@ def __init__(
name="ChitChatDialogue",
version=version,
nodes=[
default_state,
init_state,
chatting_state,
end_state,
],
edges=[
init_session,
reject_session,
start_dialogue,
cont_dialogue,
end_session,
Expand All @@ -113,23 +97,6 @@ def __init__(
cleanup_interval=cleanup_interval,
)

def on_initiate_session(self, model: Type[Model]):
"""
This handler is triggered when the initial message of the
dialogue is received. From here you can either accept or reject.
Logic that is needed to complete any kind of handshake or considers
global agent state should go here.
"""
return super()._on_state_transition(init_session.name, model)

def on_reject_session(self, model: Type[Model]):
"""
This handler is triggered when a reject message is returned on
the initial message.
Implement this if you need to clean up session data.
"""
return super()._on_state_transition(reject_session.name, model)

def on_start_dialogue(self, model: Type[Model]):
"""
This handler is triggered when an accept message is returned on
Expand Down
53 changes: 0 additions & 53 deletions integrations/fetch-ai-engine/src/ai_engine/dialogue.py

This file was deleted.

Loading
Loading