Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex AI Studio
    • All guides
    • Disabling request logging
    • Getting an API key
    • Image generation
    • Batch processing
      • Creating a voice agent
      • Creating a simple text agent
      • Creating a text agent with a function call
      • Managing Vector Store search index
  • Compatibility with OpenAI
  • Access management
  • Pricing policy
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Getting started
  • Build a chat
  1. Step-by-step guides
  2. Developing AI agents
  3. Creating a text agent with a function call

Creating a simple text agent with a function call

Written by
Yandex Cloud
Updated at October 28, 2025
  • Getting started
  • Build a chat

In Yandex AI Studio, you can create a text agent with a function call that can communicate with the user in text format and maintain a dialogue closely resembling natural human interaction.

Getting startedGetting started

To use an example:

Python

Get API authentication credentials as described in Authentication with the Yandex AI Studio API.

Build a chatBuild a chat

Python
  1. Create a file named index.py and add the following code to it:

    import openai
    from openai import OpenAI
    import json
    
    YANDEX_CLOUD_MODEL = "yandexgpt"
    
    client = openai.OpenAI(
        api_key=YANDEX_CLOUD_API_KEY,
        base_url="https://rest-assistant.api.cloud.yandex.net/v1",
        project=YANDEX_CLOUD_FOLDER
    )
    
    # 1. Listing the functions the model can call
    tools = [
        {
            "type": "function",
            "name": "get_weather",
            "description": "Getting current weather for the city you specify.",
            "parameters": {
                "type": "object",
                "properties": {
                    "city": {
                        "type": "string",
                        "description": "City, e.g.: Petersburg or Moscow",
                    },
                },
                "required": ["city"],
            },
        },
    ]
    
    # The simplest implementation of the function (can be replaced with a call to a real API)
    def get_weather(city):
        # Here you can implement an integration, e.g., with Yandex Weather
        return {
            "city": city,
            "temperature": "12 °C",
            "condition": "Cloudy, light breeze"
        }
    
    # Forming a list of messages to be updated
    input_list = [
        {"role": "user", "content": "What is the weather like in Krasnoyarsk?"}
    ]
    
    # 2. Requesting a model with specific features
    response = client.responses.create(
        model=f"gpt://{YANDEX_CLOUD_FOLDER}/{YANDEX_CLOUD_MODEL}",
        tools=tools,
        input=input_list,
    )
    
    # Adding the model's input to history
    input_list += response.output
    
    for item in response.output:
        if item.type == "function_call":
            if item.name == "get_weather":
                # 3. Executing the get_weather function
                weather_info = get_weather(**json.loads(item.arguments))
    
                # 4. Providing the result of the function back to the model
                input_list.append({
                    "type": "function_call_output",
                    "call_id": item.call_id,
                    "output": json.dumps(weather_info)
                })
    
    print("Final input:")
    for item in input_list:
        if isinstance(item, dict) and item.get("type") == "function_call_output":
            parsed = json.loads(item["output"])
            print("function_call_output:", parsed)
        else:
            print(item)
    
    response = client.responses.create(
        model=f"gpt://{YANDEX_CLOUD_FOLDER}/{YANDEX_CLOUD_MODEL}",
        instructions="Respond only with the weather data returned by the function.",
        tools=tools,
        input=input_list,
    )
    
    # 5. Final response
    print("Final output:")
    print(response.model_dump_json(indent=2))
    print("\n" + response.output_text)
    
  2. Save authentication data into environment variables:

    export YANDEX_CLOUD_FOLDER=<folder_ID>
    export YANDEX_CLOUD_API_KEY=<API_key>
    
  3. Run the file you created:

    python index.py
    

    Response example:

    Final input:
    {'role': 'user', 'content': 'What is the weather like in Krasnoyarsk?'}
    ResponseFunctionToolCall(arguments='{"city":"Krasnoyarsk"}', call_id='get_weather', name='get_weather', type='function_call', id='get_weather', status='completed', valid=True)
    function_call_output: {'city': 'Krasnoyarsk', 'temperature': '12 °C', 'condition': 'Cloudy, light breeze'}
    Final output:
    {
      "id": "70d96fac-1c4b-4f4a-9f80-56df********",
      "created_at": 1758556157206.0,
      "error": null,
      "incomplete_details": null,
      "instructions": "Respond only with the weather data returned by the function.",
      "metadata": null,
      "model": "gpt://b1gstllj8rgs********/yandexgpt",
      "object": "response",
      "output": [
        {
          "id": "f15c66e8-99a2-4647-a820-406e********",
          "content": [
            {
              "annotations": [],
              "text": "It is currently plus 12°C in Krasnoyarsk, cloudy, light breeze.",
              "type": "output_text",
              "logprobs": null,
              "valid": true
            }
          ],
          "role": "assistant",
          "status": "completed",
          "type": "message",
          "valid": true
        }
      ],
      "parallel_tool_calls": true,
      "temperature": null,
      "tool_choice": "auto",
      "tools": [
        {
          "name": "get_weather",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "description": "City, e.g.: Petersburg or Moscow"
              }
            },
            "required": [
              "city"
            ]
          },
          "strict": null,
          "type": "function",
          "description": "Getting current weather for the city you specify.",
          "valid": true
        }
      ],
      "top_p": null,
      "background": false,
      "conversation": null,
      "max_output_tokens": null,
      "max_tool_calls": null,
      "previous_response_id": null,
      "prompt": null,
      "prompt_cache_key": null,
      "reasoning": null,
      "safety_identifier": null,
      "service_tier": null,
      "status": "completed",
      "text": null,
      "top_logprobs": null,
      "truncation": null,
      "usage": null,
      "user": "",
      "valid": true
    }
    
    It is currently plus 12°C in Krasnoyarsk, cloudy, light breeze.
    

See alsoSee also

  • Overview of Yandex AI Studio AI models

Was the article helpful?

Previous
Creating a simple text agent
Next
Managing Vector Store search index
© 2025 Direct Cursus Technology L.L.C.