-
Notifications
You must be signed in to change notification settings - Fork 238
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
agentops_property - internal objects tracking the right way #506
Conversation
The function `check_call_stack_for_agent_id` is designed to search through the call stack to find an instance of a class that contains specific `AgentProperty` descriptors, particularly looking for an `agent_ops_agent_id`. Here's a step-by-step explanation:1. **Function Definition and Docstring**: - The function is defined to return either a `UUID` or `None`. - The docstring explains that it looks through the call stack for the class that called the LLM (Language Learning Model) and checks for `AgentProperty` descriptors.2. **Inspecting the Call Stack**: - The function uses `inspect.stack()` to get the current call stack, which is a list of `FrameInfo` objects representing the stack frames.3. **Iterating Through Stack Frames**: - It iterates over each `frame_info` in the call stack.4. **Accessing Local Variables**: - For each frame, it accesses the local variables using `frame_info.frame.f_locals`.5. **Checking Each Local Variable**: - It iterates over each local variable (`var_name`, `var`) in the current frame.6. **Stopping at Main**: - If the variable name is `"__main__"`, it returns `None` and stops further processing.7. **Checking for AgentProperty Descriptors**: - It tries to check if the variable (`var`) has `AgentProperty` descriptors. - It gets the type of the variable (`var_type`). - It retrieves all class attributes of `var_type` into a dictionary `class_attrs`.8. **Looking for Specific Descriptors**: - It looks for an attribute named `agent_ops_agent_id` in `class_attrs`. - If `agent_ops_agent_id` is an instance of `AgentProperty`, it retrieves the agent ID using `agent_id_desc.__get__(var, var_type)`.9. **Returning the Agent ID**: - If an agent ID is found, it optionally retrieves the agent name using a similar process and returns the agent ID. - If no agent ID is found, it continues to the next variable.10. **Handling Exceptions**: - If any exception occurs during the process, it catches the exception and continues to the next variable.11. **Returning None**: - If no agent ID is found in the entire call stack, it returns `None`.This function is useful for debugging or tracking purposes, where you need to identify the agent that initiated a particular call in a complex system. Signed-off-by: Teo <[email protected]>
Codecov ReportAttention: Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
|
The previous helper was just a helper in the middle of a For instance, say you wanna lookup
Without a descriptor, there is no way to determine whether the value accessed at |
Great catch. |
Signed-off-by: Teo <[email protected]>
I can't get |
Not good to merge. This is failing our integration with CrewAI:
Here's a good example repo to use. Use the job posting example, I find it easiest |
@teocns I think you should update the examples with the |
black is super opinionated and has no configuration. you can run it locally to see what its upset about |
daa87b9
to
91088b5
Compare
1. Renamed AgentOpsDescriptor to agentops_property; 2. Thanks to __set_name__, The descriptor will now automatically know its own name when it's assigned as a class attribute Signed-off-by: Teo <[email protected]>
91088b5
to
df9fbc5
Compare
Key Changes
Technical Details
TestingAdded comprehensive test suite covering:
|
Signed-off-by: Teo <[email protected]>
Big Win. It now comes with general pydantic support 🥳 For CrewAI, it requires the following patch; here's why: For clean code reasons I renamed the property prefix standard to
Which makes a lot more sense to contain the scope and purpose within a single snake case group @areibman let's merge this - let me know if you wanna move back to agent_ops property nomenclature for an express merge |
Signed-off-by: Teo <[email protected]>
Amazing, works for me on several CrewAI and Autogen examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff
@the-praxs second pair of eyes before merge pls? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
Introduces the
agentops_property
descriptor for safe and consistent objects tracking;The
check_call_stack_for_agent_id
function has been refactored to utilize this property descriptor improving the process of identifying agent IDs from the call stack.Property access nomenclature is standardized to
_agentops_<name>
for private attrs andagentops_<name>
for public attrs