Skip to content

Commit

Permalink
refactor: replace answers with results
Browse files Browse the repository at this point in the history
  • Loading branch information
kilativ-dotcom committed Sep 20, 2024
1 parent 5275801 commit 5c8c332
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 34 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,31 +694,31 @@ arguments = get_action_arguments(action_node, 2)
assert arguments == [argument1, dynamic_node]
```

### Create and get action answer
### Create and get action result

```python
def create_action_answer(action_node: ScAddr, *elements: ScAddr) -> None: ...
def create_action_result(action_node: ScAddr, *elements: ScAddr) -> None: ...


def get_action_answer(action_node: ScAddr) -> ScAddr: ...
def get_action_result(action_node: ScAddr) -> ScAddr: ...
```

Create and get structure with output of action

![agent answer](docs/schemes/png/agent_answer.png)
![agent result](docs/schemes/png/agent_result.png)

```python
from sc_client.constants import sc_types
from sc_kpm.utils import create_node
from sc_kpm.utils.action_utils import create_action_answer, get_action_answer
from sc_kpm.utils.action_utils import create_action_result, get_action_result
from sc_kpm.sc_sets import ScStructure

action_node = create_node(sc_types.NODE_CONST_STRUCT)
answer_element = create_node(sc_types.NODE_CONST_STRUCT)
create_action_answer(action_node, answer_element)
result = get_action_answer(action_node)
result_element = create_node(sc_types.NODE_CONST_STRUCT)
create_action_result(action_node, result_element)
result = get_action_result(action_node)
result_elements = ScStructure(result).elements_set
assert result_elements == {answer_element}
assert result_elements == {result_element}
```

### Call, execute and wait agent
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- All answers are replaced with results

## [v0.3.0]
### Changed
- All questions are replaced with actions
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/sum_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from sc_kpm.sc_sets import ScStructure
from sc_kpm.utils import create_link, get_link_content_data
from sc_kpm.utils.action_utils import (
create_action_answer,
create_action_result,
execute_agent,
finish_action_with_status,
get_action_answer,
get_action_result,
get_action_arguments,
)

Expand All @@ -45,7 +45,7 @@ def run(self, action_node: ScAddr) -> ScResult:
arg2_content = get_link_content_data(arg2_link)
if not isinstance(arg1_content, int) or not isinstance(arg2_content, int):
return ScResult.ERROR_INVALID_TYPE
create_action_answer(action_node, create_link(arg1_content + arg2_content, ScLinkContentType.INT))
create_action_result(action_node, create_link(arg1_content + arg2_content, ScLinkContentType.INT))
return ScResult.OK


Expand All @@ -67,10 +67,10 @@ def main():
wait_time=1,
)
assert is_successful
answer_struct = get_action_answer(action)
answer_link = (ScStructure(set_node=answer_struct)).elements_set.pop() # get one element
answer_content = get_link_content_data(answer_link)
logging.info("Answer received: %s", repr(answer_content))
result_struct = get_action_result(action)
result_link = (ScStructure(set_node=result_struct)).elements_set.pop() # get one element
result_content = get_link_content_data(result_link)
logging.info("Result received: %s", repr(result_content))


if __name__ == "__main__":
Expand Down
14 changes: 7 additions & 7 deletions docs/examples/sum_agent_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from sc_kpm.sc_sets import ScStructure
from sc_kpm.utils import create_link, get_link_content_data
from sc_kpm.utils.action_utils import (
create_action_answer,
create_action_result,
execute_agent,
finish_action_with_status,
get_action_answer,
get_action_result,
get_action_arguments,
)

Expand All @@ -44,7 +44,7 @@ def run(self, action_node: ScAddr) -> ScResult:
arg2_content = get_link_content_data(arg2_link)
if not isinstance(arg1_content, int) or not isinstance(arg2_content, int):
return ScResult.ERROR_INVALID_TYPE
create_action_answer(action_node, create_link(arg1_content + arg2_content, ScLinkContentType.INT))
create_action_result(action_node, create_link(arg1_content + arg2_content, ScLinkContentType.INT))
return ScResult.OK


Expand All @@ -64,10 +64,10 @@ def main():
wait_time=1,
)
assert is_successful
answer_struct = get_action_answer(action)
answer_link = ScStructure(set_node=answer_struct).elements_set.pop()
answer_content = get_link_content_data(answer_link)
logging.info("Answer received: %s", repr(answer_content))
result_struct = get_action_result(action)
result_link = ScStructure(set_node=result_struct).elements_set.pop()
result_content = get_link_content_data(result_link)
logging.info("Result received: %s", repr(result_content))


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions docs/schemes/gwf/agent_base.gwf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<GWF version="2.0">
<staticSector>
<contour type="contour/const/perm" idtf="py: answer_struct" shapeColor="0" id="22085440" parent="0" left="0" top="0" right="102.875" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" idtf_pos_x="-52" idtf_pos_y="62">
<contour type="contour/const/perm" idtf="py: result_struct" shapeColor="0" id="22085440" parent="0" left="0" top="0" right="102.875" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" idtf_pos_x="-52" idtf_pos_y="62">
<points>
<point x="210" y="435"/>
<point x="210" y="555"/>
Expand Down Expand Up @@ -30,7 +30,7 @@
<node type="node/const/perm/general" idtf="py: arguments[...]" shapeColor="0" id="15676064" parent="0" left="0" top="0" right="103.266" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="555" y="360" haveBus="false" idtf_pos="0">
<content type="0" mime_type="" content_visibility="false" file_name=""/>
</node>
<node type="node/const/perm/relation" idtf="nrel_answer" shapeColor="0" id="15659472" parent="0" left="0" top="0" right="75.375" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="180" y="375" haveBus="false" idtf_pos="0">
<node type="node/const/perm/relation" idtf="nrel_result" shapeColor="0" id="15659472" parent="0" left="0" top="0" right="75.375" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="180" y="375" haveBus="false" idtf_pos="0">
<content type="0" mime_type="" content_visibility="false" file_name=""/>
</node>
<node type="node/const/perm/general" idtf="py: action_node" shapeColor="0" id="15601856" parent="0" left="0" top="0" right="93.5313" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="270" y="330" haveBus="false" idtf_pos="1">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<GWF version="2.0">
<staticSector>
<contour type="contour/const/perm" idtf="py: answer_struct" shapeColor="0" id="34924496" parent="0" left="0" top="0" right="102.875" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" idtf_pos_x="-52" idtf_pos_y="62">
<contour type="contour/const/perm" idtf="py: result_struct" shapeColor="0" id="34924496" parent="0" left="0" top="0" right="102.875" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" idtf_pos_x="-52" idtf_pos_y="62">
<points>
<point x="210" y="435"/>
<point x="210" y="555"/>
<point x="330" y="555"/>
<point x="330" y="435"/>
</points>
</contour>
<node type="node/const/perm/relation" idtf="nrel_answer" shapeColor="0" id="39588656" parent="0" left="0" top="0" right="75.375" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="180" y="375" haveBus="false" idtf_pos="0">
<node type="node/const/perm/relation" idtf="nrel_result" shapeColor="0" id="39588656" parent="0" left="0" top="0" right="75.375" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="180" y="375" haveBus="false" idtf_pos="0">
<content type="0" mime_type="" content_visibility="false" file_name=""/>
</node>
<node type="node/const/perm/general" idtf="py: action_node" shapeColor="0" id="36806336" parent="0" left="0" top="0" right="93.5313" bottom="23" textColor="164" text_angle="0" text_font="Times New Roman" font_size="10" x="270" y="330" haveBus="false" idtf_pos="3">
Expand Down
Binary file removed docs/schemes/png/agent_answer.png
Binary file not shown.
Binary file modified docs/schemes/png/agent_base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/schemes/png/agent_result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/sc_kpm/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CommonIdentifiers:
RREL_LAST: Idtf = "rrel_last"
NREL_BASIC_SEQUENCE: Idtf = "nrel_basic_sequence"
NREL_SYSTEM_IDENTIFIER: Idtf = "nrel_system_identifier"
NREL_ANSWER: Idtf = "nrel_answer"
NREL_RESULT: Idtf = "nrel_result"
CONCEPT_FILENAME: Idtf = "concept_filename"


Expand Down Expand Up @@ -62,7 +62,7 @@ def resolve(cls) -> None:
CommonIdentifiers.RREL_LAST: sc_types.NODE_CONST_ROLE,
CommonIdentifiers.NREL_BASIC_SEQUENCE: sc_types.NODE_CONST_NOROLE,
CommonIdentifiers.NREL_SYSTEM_IDENTIFIER: sc_types.NODE_CONST_NOROLE,
CommonIdentifiers.NREL_ANSWER: sc_types.NODE_CONST_NOROLE,
CommonIdentifiers.NREL_RESULT: sc_types.NODE_CONST_NOROLE,
CommonIdentifiers.CONCEPT_FILENAME: sc_types.NODE_CONST_CLASS,
ActionStatus.ACTION_INITIATED: sc_types.NODE_CONST_CLASS,
ActionStatus.ACTION_FINISHED: sc_types.NODE_CONST_CLASS,
Expand Down
10 changes: 5 additions & 5 deletions src/sc_kpm/utils/action_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ def get_action_arguments(action_node: ScAddr, count: int) -> List[ScAddr]:
return arguments


def create_action_answer(action_node: ScAddr, *elements: ScAddr) -> None:
answer_struct_node = ScStructure(*elements).set_node
create_norole_relation(action_node, answer_struct_node, ScKeynodes[CommonIdentifiers.NREL_ANSWER])
def create_action_result(action_node: ScAddr, *elements: ScAddr) -> None:
result_struct_node = ScStructure(*elements).set_node
create_norole_relation(action_node, result_struct_node, ScKeynodes[CommonIdentifiers.NREL_RESULT])


def get_action_answer(action_node: ScAddr) -> ScAddr:
def get_action_result(action_node: ScAddr) -> ScAddr:
templ = ScTemplate()
templ.triple_with_relation(
action_node,
sc_types.EDGE_D_COMMON_VAR >> ScAlias.RELATION_EDGE,
sc_types.NODE_VAR_STRUCT >> ScAlias.ELEMENT,
sc_types.EDGE_ACCESS_VAR_POS_PERM,
ScKeynodes[CommonIdentifiers.NREL_ANSWER],
ScKeynodes[CommonIdentifiers.NREL_RESULT],
)
if search_results := client.template_search(templ):
return search_results[0].get(ScAlias.ELEMENT)
Expand Down

0 comments on commit 5c8c332

Please sign in to comment.