Skip to content

Commit ecf1d17

Browse files
committed
Converting openai_session_example (WIP)
1 parent 889c203 commit ecf1d17

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

samples-v2/openai_agents/function_app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,9 @@ async def random_number_tool(max: int) -> int:
115115
def message_filter(context):
116116
import handoffs.message_filter
117117
return handoffs.message_filter.main(context.create_activity_tool(random_number_tool))
118+
119+
@app.orchestration_trigger(context_name="context")
120+
@app.durable_openai_agent_orchestrator
121+
def openai_session_example(context):
122+
import memory.openai_session_example
123+
return memory.openai_session_example.main()

samples-v2/openai_agents/memory/openai_session_example.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from agents import Agent, OpenAIConversationsSession, Runner
1111

1212

13-
async def main():
13+
def main():
1414
# Create an agent
1515
agent = Agent(
1616
name="Assistant",
@@ -26,7 +26,7 @@ async def main():
2626
# First turn
2727
print("First turn:")
2828
print("User: What city is the Golden Gate Bridge in?")
29-
result = await Runner.run(
29+
result = Runner.run_sync(
3030
agent,
3131
"What city is the Golden Gate Bridge in?",
3232
session=session,
@@ -37,14 +37,14 @@ async def main():
3737
# Second turn - the agent will remember the previous conversation
3838
print("Second turn:")
3939
print("User: What state is it in?")
40-
result = await Runner.run(agent, "What state is it in?", session=session)
40+
result = Runner.run_sync(agent, "What state is it in?", session=session)
4141
print(f"Assistant: {result.final_output}")
4242
print()
4343

4444
# Third turn - continuing the conversation
4545
print("Third turn:")
4646
print("User: What's the population of that state?")
47-
result = await Runner.run(
47+
result = Runner.run_sync(
4848
agent,
4949
"What's the population of that state?",
5050
session=session,
@@ -72,7 +72,3 @@ async def main():
7272
all_items = await session.get_items()
7373
# print(all_items)
7474
print(f"Total items in session: {len(all_items)}")
75-
76-
77-
if __name__ == "__main__":
78-
asyncio.run(main())

0 commit comments

Comments
 (0)