Skip to main content
Loading navigation
Back to prompt library

Implement Tool Functionality and Thread Management

Linked challenge: Build a Proactive Executive Assistant Agent with OpenAI Agents SDK

Prompt source

implementation16 lines4 sectionsNo variables1 code block
Develop the actual Python functions that back your `schedule_calendar_event` and `send_short_email` tools. For `schedule_calendar_event`, simulate interaction with a calendar API (or use a placeholder list of events). For `send_short_email`, simply print the email details to the console. Then, create an OpenAI `Thread` and test the agent's ability to process a user request that requires tool use, such as scheduling a meeting. Ensure your tool outputs are fed back into the thread.

```python
def schedule_calendar_event(title: str, start_time: str, end_time: str, attendees: list[str]):
    # Simulate calendar API call or add to a dummy list
    print(f'Simulating calendar event creation: {title} from {start_time} to {end_time} with {attendees}')
    return {'status': 'success', 'event_id': 'evt_12345'}

def send_short_email(recipient: str, subject: str, body: str):
    # Simulate email sending
    print(f'Simulating email to {recipient} with subject "{subject}" and body: {body}')
    return {'status': 'success', 'message_id': 'msg_67890'}

# Example of running an assistant thread
# thread = client.beta.threads.create()
# client.beta.threads.messages.create(thread_id=thread.id, role='user', content='...')
# run = client.beta.threads.runs.create(thread_id=thread.id, assistant_id=assistant.id)
# ... manage run status and tool outputs ...
```