Examples

Post to X (Twitter) using MultiOn Agent API

This example goes over how to use our Agent API to post to X (Twitter).

Install our Agent Browser Extension for Local Development

The extension is a powerful tool for local development, providing a bridge between your code and the MultiOn automation capabilities.

Easy Installation: Find it on the Chrome Web Store and click “Add to Chrome” to add it to your browser - MultiOn Browser Extension.

Install Required Packages

Ensure you have the necessary packages installed by running the following commands in your terminal:

$pip install multion

Import Required Libraries

In your Python script, import the required libraries for the example:

1import multion

Initialize Multion Client

1from multion.client import MultiOn
2
3multion = MultiOn(api_key="MULTION_API_KEY")

Autonomous mode: Browse

Create a new local session to initiate posting on twitter autonomously:

1response = multion.browse(
2 cmd="post 'hello world - I love multion' on twitter",
3 url="https://twitter.com",
4 local=True
5)
6print(response.message)

Step mode: Create a New Session

Create a new local session to initiate posting on twitter in step mode:

1create_session_response = multion.sessions.create(
2 url="https://twitter.com",
3 local=True
4)
5session_id = create_session_response.session_id
6print(create_session_response.message)

Update Session

If needed, update the session with additional information:

1prompt = "Please post 'Hi from MultiOn Agent API. '"
2url = "https://twitter.com"
3while response.status == 'CONTINUE':
4 response = multion.sessions.step(
5 session_id = session_id,
6 cmd=prompt,
7 url=url
8 )
9print(response.message)

You can see the screenshot of each step in response.screenshot

View session screenshot

1get_screenshot = multion.sessions.screenshot(session_id=session_id)
2print("session screenshot: ", get_screenshot.screenshot)

Close Session

Finally, close the session when done:

1close_session_response = multion.sessions.close(session_id=session_id)
2print("close_session_response: ", close_session_response)

Thank you for exploring this MultiOn Agent API example. Should you have any questions, feel free to reach out on our Discord channel or directly to our team. Happy building! 😊