Skip to content

function call can not get call_id #559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
goooodle opened this issue Apr 21, 2025 · 5 comments
Closed

function call can not get call_id #559

goooodle opened this issue Apr 21, 2025 · 5 comments
Labels
enhancement New feature or request question Question about using the SDK stale

Comments

@goooodle
Copy link

goooodle commented Apr 21, 2025

return FunctionTool(
name=tool_name,
description=tool_desc,
params_json_schema=params_schema,
on_invoke_tool=create_run_function(service_key, service_name),
strict_json_schema=is_service_tool,
)

def create_run_function(service_key: str, service_name: str):
async def run_function(context, params_str: str) -> str:

  #当执行多个相同方法名,但是参数不同时,这里无法定位到是哪次调用, 因为该方法无法获取call_id
  #When multiple methods with the same name but different parameters are executed, it is impossible to 
      determine which call it is here because the method cannot obtain the call_id

    params = json.loads(params_str)

    try:
        result = await call_service(service_key=service_key, params=params)
       # context.context[call_id]["invoke_status"] = "success"
        return json.dumps(result, ensure_ascii=False)
    except Exception as e:
       # context.context[call_id]["invoke_status"] = "error"
        return f"Error executing tool: {str(e)}"

return run_function

Question

当执行多个相同方法名,但是参数不同时,这里无法定位到是哪次调用, 因为该方法无法获取call_id
When multiple methods with the same name but different parameters are executed, it is impossible to determine which call it is here because the method cannot obtain the call_id

@goooodle goooodle added the question Question about using the SDK label Apr 21, 2025
@rm-openai
Copy link
Collaborator

Yeah, from the point of view of this SDK, multiple functions with the same name is an error. LLMs will generally have trouble with functions named the same; what's the use case?

@goooodle
Copy link
Author

goooodle commented Apr 22, 2025

async def mock_execute(service_key, params:str):
    return '400'

def create_run_function(service_key: str, service_name: str):
    async def run_function(context, params_str: str) -> str:
        try:
           result = await mock_execute(service_key=service_key, params=params_str)
           # context.context[call_id]["invoke_status"] = "success"   // log process status, but cant not get call_id
           return result
        except Exception as e:
           # context.context[call_id]["invoke_status"] = "error"  // log process status, but cant not get call_id
          return f"Error executing tool: {str(e)}"
    return run_function


class FunctionArgs(BaseModel):
    product_name: str

async def main():
    tools = []
    tools.append(FunctionTool(
        name='query_price',
        description='query price',
        params_json_schema=FunctionArgs.model_json_schema(),
        on_invoke_tool=create_run_function('query_price', 'query price'),
        strict_json_schema=True,
    ))

    agent = Agent(
        name="gpt-4.1",
        instructions="You are a helpful assistant.",
        tools=tools
    )

    agent_result = await Runner.run(
        agent,
        input='query the prices of  macbook pro m1 and  macbook pro m2 ',
        context={})
    result = agent_result.final_output

if __name__ == "__main__":
    asyncio.run(main())

The function query_price was called twice, with the following parameters: macbook pro m1 , Another parameter is: macbook pro m2,
I want to get the execution status of this function, but I can't get it because I can't get call_id in 'run_function' function

@rm-openai
Copy link
Collaborator

Ah got it. You want the call ID for some logging. Unfortunately we don't expose this right now. We could add it as an optional param to the on_invoke_tool - PR welcome!

@rm-openai rm-openai added the enhancement New feature or request label Apr 22, 2025
Copy link

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale label Apr 30, 2025
Copy link

github-actions bot commented May 4, 2025

This issue was closed because it has been inactive for 3 days since being marked as stale.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Question about using the SDK stale
Projects
None yet
Development

No branches or pull requests

2 participants