import openai
oai = openai.OpenAI()
messages = [
{"role": "system", "content": "You have access to persistent memory. Use store_memory to save important facts and recall_memory to retrieve them."},
{"role": "user", "content": "My name is Alex and I work at Acme Corp. Remember that."},
]
response = oai.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tools,
)
# Handle tool calls
for tool_call in response.choices[0].message.tool_calls or []:
result = handle_tool_call(
client,
agent_id="openai-agent",
tool_name=tool_call.function.name,
arguments=tool_call.function.arguments,
)
# Append the tool result back to the conversation
messages.append(response.choices[0].message)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": result,
})
# Continue the conversation with the tool results
final_response = oai.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=tools,
)
print(final_response.choices[0].message.content)