qijia / marvin_test.py
zh3036's picture
initilize with ok pydantic ai
1372721
import marvin
import json
# define two speakers
alice = marvin.Agent(name="Alice", instructions="You are a coach, speak like coach, start with question if no convo history ; you speak very concicely, one sentence at a time")
bob = marvin.Agent(name="Bob", instructions="You have a problem with your kids. and speak very concicely, one sentence at a time")
# simple ping-pong loop
conversation = []
for _ in range(3):
alice_msg = marvin.run("Your want to ask bob questions, help bob", agents=[alice], context={"history": conversation})
conversation.append(("Alice", alice_msg))
bob_msg = marvin.run("Respond to Alice with your problem", agents=[bob], context={"history": conversation})
conversation.append(("Bob", bob_msg))
print(conversation)
input("Press Enter to continue...")
# Convert conversation to a string format for the critic
conversation_text = "\n\n".join([f"{speaker}: {message}" for speaker, message in conversation])
# third agent evaluates
critic = marvin.Agent(
name="Critic",
instructions=(
"Score the dialogue on insight (0-10) and civility (0-10); "
"return JSON with fields 'insight', 'civility', 'comment'."
)
)
score = marvin.run(f"Please evaluate this conversation:\n\n{conversation_text}", agents=[critic], result_type=dict)
print(score)
# Write score to file
with open('score.json', 'w') as f:
json.dump(score, f, indent=2)